﻿var IsMenuShown=false;
var itemTableDeferred=null;
var itemTable=null;
var imageCell=null;
var onKeyPress=false;
var currentCtx=null;
var currentItemID=null;
var cpmode = null;
function escapeProperly(str)
{
	return escapeProperlyCoreCore(str, false, false, false);
}
function escapeProperlyCore(str, bAsUrl)
{
	return escapeProperlyCoreCore(str, bAsUrl, false, false);
}

function OpenPopup(url)
{
    return window.showModalDialog(url,null,"");
}
function GoToURL(ctr)
{
    GoToPage(ctr.href);
}

function NewItem(url)
{
	GoToPage(url);
}
function EditItem(url)
{
	GoToPage(url);
}

function IsKeyDownSubmit(event)
{
	if (event !=null)
	{
		var charCode;
		var bKeyModifiers;
		if (browseris.ie)
		{
			charCode=event.keyCode;
			bKeyModifiers=event.altKey || event.ctrlKey;
		}
		else
		{
			charCode=event.which;
			bKeyModifiers=event.modifers &
						   (event.ALT_MASK | event.CONTROL_MASK);
		}
		if ((charCode==13) && !bKeyModifiers)
			return true;
	}
	return false;
}

function AlertAndSetFocus(msg, fieldName)
{
	fieldName.focus();
	fieldName.select();
	window.alert(msg);
}
function AlertAndSetFocusForDropdown(msg, fieldName)
{
	fieldName.focus();
	window.alert(msg);
}

function HandleKey()
{
	var key=event.keyCode;
	var ctrl=event.srcElement;
	var str=ctrl.value;
	var opt=EnsureSelectElement(ctrl, ctrl.opt);
	var bNeedMatch=false;
	var strLower;
	var strMatchLower;
	switch (key)
	{
	case 8:
		if (str.length > 0)
		{
			str=str.substr(0, str.length - 1);
		}
		bNeedMatch=true;
		break;
	case 16:
	case 17:
	case 18:
		return;
	case 9:
	case 16:
	case 17:
	case 18:
		return;
	case 13:
		strLower=ctrl.value.toLocaleLowerCase();
		strMatchLower=ctrl.match.toLocaleLowerCase();
		if (strMatchLower.indexOf(strLower) !=0)
			ctrl.match=FilterChoice(opt, ctrl, ctrl.value, "");
		if (opt.style.display !="none")
		{
			ctrl.value=ctrl.match;
			opt.style.display="none";
			event.returnValue=false;
		}
		return;
	case 27:
		opt.style.display="none";
		event.returnValue=false;
		return;
	case 38:
		if (opt.style.display !="none")
		{
			if (opt.selectedIndex > 0)
				opt.selectedIndex=opt.selectedIndex - 1;
			else
				opt.selectedIndex=opt.options.length - 1;
			SetCtrlMatch(ctrl, opt);
			event.returnValue=false;
		}
		return;		
	case 40:
		if (opt.style.display !="none" && opt.selectedIndex < opt.options.length - 1)
		{
			opt.selectedIndex=opt.selectedIndex+1;
			SetCtrlMatch(ctrl, opt);
			event.returnValue=false;
			return;
		}
		bNeedMatch=true;
		break;
	case 46:
		break;
	default:
		break;
	}
	if (bNeedMatch);
		ctrl.match=FilterChoice(opt, ctrl, str, "");
}

var deleteInstance=0;
var L_Edit_Text="";
var L_ViewItem_Text="Xem nội dung";
var L_EditItem_Text="Sửa đổi nội dung";
var L_EditSeriesItem_Text="Edit Series";
var L_DeleteItem_Text="Are you sure you want to delete this item?";
var L_Subscribe_Text="Trả lại";
var L_MngPerms_Text="Gửi lên";
function resetExecutionState()
{
	IsMenuShown=false;
	itemTable=null;
	EndDeferItem();
	imageCell=null;
	onKeyPress=false;
	currentCtx=null;
	currentEditMenu=null;
	currentItemID=null;	
	cpmode = null;
}
function IsMenuEnabled()
{
	return (browseris.ie55up || browseris.nav6up || browseris.safari125up);
}
function GetSelectedElement(elem, tagName)
{
	while(elem !=null && elem.tagName !=tagName)
		elem=elem.parentNode;
	return elem;
}
function setupMenuContext(ctx)
{
	currentCtx=ctx;
}
function FindSTSMenuTable(elm, strSearch)
{
	var str=elm.getAttribute(strSearch);
	while (elm !=null && (str==null ||str==""))
	{
		elm=GetSelectedElement(elm.parentNode, "TABLE");
		if (elm !=null)
			str=elm.getAttribute(strSearch);
	}
	return elm;
}
function OnLinkDeferCall(elm)
{
	if (!IsMenuEnabled())
		return false;
	elm.onblur=OutItem;
	elm.onkeydown=PopMenu;
	var elmTmp=FindSTSMenuTable(elm, "CTXName");
	if (elmTmp==null)
		return false;
	OnItem(elmTmp);
	return false;
}
function StartDeferItem(elm)
{
	if (elm !=itemTable)
	{
		itemTableDeferred=elm;
		elm.onmouseout=EndDeferItem;
		elm.onclick=DeferredOnItem;
		elm.oncontextmenu=DeferredOnItem;
	}
}
function DeferredOnItem(e)
{
	var elm=itemTableDeferred;
	if (elm !=null)
	{
		MenuHtc_hide();
		OnItem(elm);
		CreateMenu(e);
		return false;
	}
}
function EndDeferItem()
{
	var elm=itemTableDeferred;
	if (elm !=null)
	{
		itemTableDeferred=null;
		elm.onmouseout=null;
		elm.onclick=null;
		elm.oncontextmenu=null;
	}
}
function GetFirstChildElement(e)
{
	for (var i=0; i < e.childNodes.length; i++)
	{
		if (e.childNodes[i].nodeType==1)
			return e.childNodes[i];
	}
	return null;
}
function GetLastChildElement(e)
{
	for (var i=e.childNodes.length-1; i >=0; i--)
	{
		if (e.childNodes[i].nodeType==1)
			return e.childNodes[i];
	}
	return null;
}
function OnItemDeferCall(elm)
{
	if (!IsMenuEnabled())
		return false;
	if (IsMenuOn())
	{
		StartDeferItem(elm);
		return false;
	}
	if (itemTable !=null)
		OutItem();
	itemTable=elm;
	currentItemID=GetAttributeFromItemTable(itemTable, "ItemId", "Id");
	cpmode = GetAttributeFromItemTable(itemTable, "cpmode", "Id"); 	
	var createCtx=new Function("setupMenuContext("+itemTable.getAttribute("CTXName")+");");
	createCtx();
	var ctx=currentCtx;
	if (browseris.nav6up)
		itemTable.className="ms-selectedtitlealternative";
	else
		itemTable.className="ms-selectedtitle";
	if (browseris.ie5up && !browseris.ie55up)
	{
		itemTable.onclick=EditMenuDefaultForOnclick;
		itemTable.oncontextmenu=EditMenuDefaultForOnclick;
	}
	else
	{
		itemTable.onclick=CreateMenu;
		itemTable.oncontextmenu=CreateMenu;
	}
	itemTable.onmouseout=OutItem;
	var titleRow;
	titleRow=GetFirstChildElement(GetFirstChildElement(itemTable));
	if (titleRow !=null)
	{
		imageCell=GetLastChildElement(titleRow);
	}
	if (ctx.listTemplate==200)
	{
		if (itemTable.getAttribute("menuType")=="Orphaned")
			downArrowText=L_Reschedule_Text;
	}
	else
		downArrowText=L_Edit_Text;
	var imageTag=GetFirstChildElement(imageCell);
	imageTag.src=ctx.imagesPath+ "menudark.gif";
	imageTag.alt=downArrowText;
	imageTag.style.visibility="visible";
	imageCell.className="ms-menuimagecell";	
	return false;
}
function OutItem()
{
	if (!IsMenuOn() && itemTable !=null)
	{
		itemTable.className="ms-unselectedtitle";
		itemTable.onclick=null;
		itemTable.oncontextmenu=null;
		itemTable.onmouseout=null;
		if (imageCell !=null)
		{
			GetFirstChildElement(imageCell).style.visibility="hidden";
			imageCell.className="";
		}
		resetExecutionState();
	}
}
function IsMenuOn()
{
	if (!IsMenuShown)
		return false;
	var fIsOpen=false;
	fIsOpen=MenuHtc_isOpen(currentEditMenu);
	if (!fIsOpen)
		IsMenuShown=false;
	return fIsOpen;
}
function PopMenu(e)
{
	if (!IsMenuEnabled())
		return true;
	if (e==null)
		e=window.event;
	var nKeyCode;
	if (browseris.nav6up)
		nKeyCode=e.which;
	else
		nKeyCode=e.keyCode;
	if (!IsMenuOn() && ((e.shiftKey && nKeyCode==13) || (e.altKey && nKeyCode==40)))
	{
		onKeyPress=true;
		CreateMenu(e);
		onKeyPress=false;
		return false;
	}
	else
		return true;
}
function CreateMenuEx(ctx, container, e)
{
	if (container==null)
		return;
	IsMenuShown=true;
	document.body.onclick="";
	var m;
	m=CMenu(currentItemID+"_menu");
	if (!m)
		return;
	
	AddListMenuItems(m, ctx);	
	currentEditMenu=m;
	container.onmouseout=null;
	OMenu(m, container, null, null, -1);
	itemTable=GetSelectedElement(container, "TABLE");
	m._onDestroy=OutItem;
	e.cancelBubble=true;
	return false;
}
function CreateMenu(e)
{
	if (!IsContextSet())
		return;
	var ctx=currentCtx;
	if (e==null)
		e=window.event;
	var srcElement=e.srcElement ? e.srcElement : e.target;
	if (itemTable==null || imageCell==null ||
		(onKeyPress==false &&
		 (srcElement.tagName=="A" ||
		  srcElement.parentNode.tagName=="A")))
		return;
	return CreateMenuEx(ctx, itemTable, e);
}

//var arr = new Array(true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true);


function AddListMenuItems(m, ctx)
{         
	VC_AddMenuItem(m,ctx,"Xem trước","newitem.gif","openpreview('/PhotoAlbumPreview.aspx?PhotoAlbum_ID=" + currentItemID + "',600,300)");
	if (arr[14])
	{
	    VC_AddMenuItem(m,ctx,"Sửa nội dung","edititem.gif","EditNews('" + currentItemID + "')");
	}
    if (arr[15])
	{	    
	    VC_AddMenuItem(m,ctx,"Xem comment trả bài","approval.gif","openpreview('/ViewCommentAlbum.aspx?PhotoAlbum_ID="+currentItemID+"',540,228)");	  
	}
	
	//if (arr[11])VC_AddMenuItem(m,ctx,"Xem nhận xét",null,itemTable.getAttribute("btnHistory"));
	if (arr[13])
	{
	    CAMSep(m);
	    VC_AddMenuItem(m,ctx,"Xóa","delete.gif","if (confirm('Bạn có muốn xóa không?')){" + itemTable.getAttribute("btnDelete") + "}");
	}
	if (arr[12]) VC_AddMenuItem(m,ctx,"Xóa Tạm",null,"if (confirm('Bạn có muốn xóa tạm không')){" + itemTable.getAttribute("btnTempDelete") + "}");
	if (arr[10]) VC_AddMenuItem(m,ctx,"Gỡ bỏ","whitearrow.gif","if (confirm('Bạn có muốn gỡ bỏ không?')){" +itemTable.getAttribute("btnDisApproval") + "}");	
		
	if (arr[8])
	{
	    CAMSep(m);
	    VC_AddMenuItem(m,ctx,"Trả về","DOWNLOAD.GIF","openpreview('/ReturnCommentAlbum.aspx?PhotoAlbum_ID=" + currentItemID + "',540,228)");
	    //VC_AddMenuItem(m,ctx,"Trả về","DOWNLOAD.GIF","alert()");
	}
	if (arr[7])	VC_AddMenuItem(m,ctx,"Gửi lên","REPORTUP.GIF","if (confirm('Bạn có muốn gửi bài lên')){" + itemTable.getAttribute("btnSendUp")+"}");
	if (arr[9])	VC_AddMenuItem(m,ctx,"Xuất bản","CheckNames.gif","if (confirm('Bạn có muốn xuất bản không?')){" + itemTable.getAttribute("btnApproval") +"}");		
	
}



function vc_Action(att,msg)
{      
	return itemTable.getAttribute(att);
}
function VC_AddMenuItem(m,ctx,text,img,action)
{	
	strDisplayText= text;
	strAction=action;
	strImagePath= ctx.imagesPath + img;
	if (img == null) strImagePath = null;
	menuOption=CAMOpt(m, strDisplayText, strAction, strImagePath, null, 5);
	menuOption.id="ID_Subscribe";
}

function vc_OpenWindow(id)
{
    
    window.open("/PrintView.aspx?news=" + id);
}
function GoToActionForm(elmID,action)
{
    if (confirm(L_DeleteItem_Text))
        location.href = "?Action=" + action + "&News_ID=" + elmID + "&Source=" + GetSource();
}

function GetRootFolder(ctx)
{
	var RootFolder=GetUrlKeyValue("RootFolder", true);
	if (RootFolder=="" || bValidSearchTerm)
	{
		var FileDirRef;
		if (itemTable)
			FileDirRef=GetAttributeFromItemTable(itemTable, "DRef", "FileDirRef");
		if (FileDirRef !=null)
			RootFolder="/"+FileDirRef;
		else
			RootFolder=ctx.listUrlDir;
		RootFolder=escapeProperly(RootFolder);
	}
	return "&RootFolder="+RootFolder;
}
function HasRights(requiredH, requiredL)
{
	if(currentItemPermMaskH==null)
	{
		if (itemTable==null) return true;
		var pmStr=GetAttributeFromItemTable(itemTable, "Perm", "PermMask");
		if(pmStr==null) return true;
		var currentItemAuthor=itemTable.getAttribute("Author");
		SetCurrentPermMaskFromString(pmStr, currentItemAuthor);
	}
	if(!currentItemCanModify
		&& (EqualRights(requiredH, requiredL, 0x0, 0x4)
		|| EqualRights(requiredH, requiredL, 0x0, 0x8)
		|| EqualRights(requiredH, requiredL, 0x40000000, 0x0)))
	{
		return false;
	}
	return (((requiredL & currentItemPermMaskL)==requiredL)
	&& ((requiredH & currentItemPermMaskH)==requiredH));
}
function EqualRights(rightsH1, rightsL1, rightsH2, rightsL2)
{
	return ((rightsH1==rightsH2) && (rightsL2==rightsL2));
}


function AddManagePermsMenuItem(m, ctx, listId, url)
{
	if(!HasRights(0x40000000, 0x0) || currentItemIsEventsExcp)
		return;
	strDisplayText=L_MngPerms_Text;
	strAction="NavigateToManagePermsPage('"+ctx.HttpRoot+"', '"+listId+"','"+url+"')";
	strImagePath=ctx.imagesPath+"manageperm.gif";
	var menuOption=CAMOpt(m, strDisplayText, strAction, strImagePath, null, 250);
	menuOption.id="ID_MngPerms";
}




function IsContextSet()
{
	if (currentCtx==null)
		return false;
	else if (currentCtx.isExplictLogin)
		return true;
	else if (currentCtx.HttpPath==null || currentItemID==null)
		return false;
	return true;
}
function ChangeContentType(id)
{
	var obj=document.getElementById(id);
	var strUrl=window.location.href;
	var idxQuery=strUrl.indexOf("?");
	if (strUrl.indexOf("?") <=0)
	{
		strUrl=strUrl+"?ContentTypeId="+obj.value;
	}
	else if (strUrl.indexOf("&ContentTypeId=") <=0)
	{
		strUrl=strUrl+"&ContentTypeId="+obj.value;
	}
	else
	{
		var pattern=/&ContentTypeId=[^&]*/i;
		strUrl=strUrl.replace(pattern,"&ContentTypeId="+obj.value);
	}
	STSNavigate(strUrl);
}

var L_EmptySlideShow_Text="No pictures found in the library. Add pictures and try again.";
var L_NotOurView_Text="This operation cannot be completed within current view. Please select another view and try again.";
function IsImgLibJssLoaded()
{
	if (typeof(fImglibJssLoaded) !="undefined")
		return fImglibJssLoaded;
	return false;
}
function EditSelectedImages()
{
	if (!IsImgLibJssLoaded())
	{
		alert(L_NotOurView_Text);
		return;
	}
	_EditSelectedImages();
}
function DeleteImages()
{
	if (!IsImgLibJssLoaded())
	{
		alert(L_NotOurView_Text);
		return;
	}
	_DeleteImages();
}

function GetPageUrl(fHomePage)
{
	return unescapeProperly(fHomePage ? g_webUrl : g_pageUrl);
}
function MtgNavigate(instanceId)
{
	if (instanceId==g_instanceId)
		return;
	var fHomePage=!g_fPageGlobal;
	window.location.href=GetPageUrl(fHomePage)+'?InstanceID='+instanceId+'&'+g_thispagedata;
}

function SetCookie(name, value, path)
{
	document.cookie=name+"="+value+";path="+path;
}




var L_OpenMenu_Text="Open Menu";
function resetFilterMenuState()
{
	if (bMenuLoadInProgress)
		return;
	bIsFilterMenuShown=false;
	bIsFilterDataLoaded=false;
	filterTable=null;
	filterImageCell=null;
	currentFilterMenu=null;
	loadingFilterMenu=null;
	ctxFilter=null;
	bIsFilterKeyPress=false;
}
function setupFilterMenuContext(ctx)
{
	ctxFilter=ctx;
}
function IsFilterMenuOn()
{
	if (!bIsFilterMenuShown)
		return false;
	var bIsOpen=false;
	bIsOpen=MenuHtc_isOpen(currentFilterMenu) || MenuHtc_isOpen(loadingFilterMenu);
	if (!bIsOpen)
		bIsFilterMenuShown=false;
	return bIsOpen;
}
function IsFilterMenuEnabled()
{
	return true;
}
function OnMouseOverFilterDeferCall(elm)
{
	if (!IsFilterMenuEnabled())
		return false;
	if (IsFilterMenuOn())
		return false;
	if (window.location.href.search("[?&]Filter=1") !=-1)
		return false;
	if (elm.FilterDisable=="TRUE")
		return false;
	if (filterTable !=null)
		OnMouseOutFilter();
	filterTable=elm;
	var createCtx=new Function("setupFilterMenuContext(ctx"+filterTable.getAttribute('CtxNum')+");");
	createCtx();
	filterTable.className="ms-selectedtitle";
	filterTable.onclick=CreateFilterMenu;
	filterTable.oncontextmenu=CreateFilterMenu;
	filterTable.onmouseout=OnMouseOutFilter;
	var titleRow=filterTable.childNodes[0].childNodes[0];
	filterImageCell=titleRow.childNodes[titleRow.childNodes.length - 1];
	var filterArrow=filterImageCell.childNodes[0];
	filterArrow.src=ctxFilter.imagesPath+"menudark.gif";
	filterArrow.alt=L_OpenMenu_Text;
	filterArrow.style.visibility="visible";
	if (IsElementRtl(filterTable))
	{
		filterImageCell.style.right=null;
		filterImageCell.style.left="1px";
	}
	else
	{
		filterImageCell.style.left=null;
		filterImageCell.style.right="1px";
	}
	filterImageCell.className="ms-menuimagecell";
	return true;
}
function OnMouseOutFilter()
{
	if (!IsFilterMenuOn() && filterTable !=null)
	{
		filterTable.className="ms-unselectedtitle";
		filterTable.onclick="";
		filterTable.oncontextmenu="";
		filterTable.onmouseout="";
		if (filterImageCell !=null)
		{
			filterImageCell.childNodes[0].style.visibility="hidden";
			filterImageCell.className="";
		}
		resetFilterMenuState();
	}
}
function OnFocusFilter(elm)
{
	if (window.location.href.search("[?&]Filter=1") !=-1)
		return false;
	if (!IsFilterMenuEnabled())
		return false;
	elm.onblur=OnMouseOutFilter;
	elm.onkeydown=PopFilterMenu;
	var elmTmp=FindSTSMenuTable(elm, "CTXNum");
	if (elmTmp==null)
		return false;
	OnMouseOverFilter(elmTmp);
	return false;
}
function PopFilterMenu(e)
{
	if (!IsFilterMenuEnabled())
		return true;
	if (e==null)
		e=window.event;
	var nKeyCode;
	if (browseris.nav6up)
		nKeyCode=e.which;
	else
		nKeyCode=e.keyCode;
	if (!IsFilterMenuOn() && ((e.shiftKey && nKeyCode==13) || (e.altKey && nKeyCode==40)))
	{
		CreateFilterMenu(e);
		return false;
	}
	else
		return true;
}
function CreateFilterMenu(e)
{
	if (filterTable==null || filterImageCell==null)
		return true;
	if (e==null)
		e=window.event;
	bIsFilterMenuShown=true;
	window.document.body.onclick="";
	currentFilterMenu=CMenu("filter_menu");
	loadingFilterMenu=CMenu("filter_menu_loading");
	currentFilterMenu.setAttribute("CompactMode", "true");
	addSortMenuItems(currentFilterMenu, loadingFilterMenu);
	if (filterStr==null)
		addFilterMenuItems(currentFilterMenu, loadingFilterMenu);
	else
		addAdHocFilterMenuItems(currentFilterMenu, loadingFilterMenu);
	e.cancelBubble=true;
	return false;
}
function GetUrlWithNoSortParameters(strSortFields)
{
	var url=window.location.href;
	var strT;
	var ichStart=0;
	var ichEqual;
	var ichAmp;
	do
	{
		ichEqual=strSortFields.indexOf("=", ichStart);
		if (ichEqual==-1)
			return url;
		strT=strSortFields.substring(ichStart, ichEqual);
		if (strT !="");
			url=RemoveQueryParameterFromUrl(url, strT);
		ichAmp=strSortFields.indexOf("&", ichEqual+1);
		if (ichAmp==-1)
			return url;
		ichStart=ichAmp+1;
	} while (strT !="");
	return url;
}


function getFilterValueFromUrl(strUrl, strFilterField)
{
	var ichStart, ichEnd;
	var strFilterFieldUrl;
	ichStart=strUrl.indexOf("=");
	if (ichStart==-1)
		return;
	ichEnd=strUrl.indexOf("&");
	if (ichEnd==-1)
		return;
	if (ichEnd < ichStart)
		return;
	strUrl=CanonicalizeUrlEncodingCase(strUrl);
	strFilterFieldUrl=strUrl.substring(ichStart+1, ichEnd);
	if (strFilterFieldUrl==strFilterField)
	{
		var strUnescaped;
		ichStart=strUrl.indexOf("=", ichEnd+1);
		if (ichStart==-1)
			return;
		strUnescaped=strUrl.substr(ichStart+1);
		strUnescaped=unescapeProperly(strUnescaped);
		return strUnescaped;
	}
	return null;
}
function OnIframeLoad()
{
	bMenuLoadInProgress=false;
	if (filterTable !=null && filterTable.getAttribute('Name') !=null)
	{
		var iframe=window.frames["FilterIframe"+filterTable.getAttribute('CtxNum')];
		if (iframe !=null)
		{
			var strFieldName=filterTable.getAttribute('Name');
			var select=iframe.document.getElementById("diidFilter"+strFieldName);
			strFieldName=escapeProperly(strFieldName);
			if (select !=null)
			{
				var c=select.childNodes.length;
				if (c > 500)
				{
					addFilterOptionMenuItem();
				}
				else
				{
					var rgChoices=select.childNodes;
					for (var i=1; i < c; i++)
					{
						var strMenuText;
						if (rgChoices[i].innerText)
							strMenuText=rgChoices[i].innerText;
						else if (rgChoices[i].textContent)
							strMenuText=rgChoices[i].textContent;
						else
							strMenuText=rgChoices[i].innerHTML;
						var strFilterUrl="javascript:SubmitFormPost('"+							STSScriptEncode(FilterFieldV3(ctxFilter.view, strFieldName, rgChoices[i].value, i, true))+"')";
						var mi=CAMOpt(currentFilterMenu, strMenuText, strFilterUrl);
						if (strFilteredValue !=null && strFilteredValue==rgChoices[i].value)
							mi.setAttribute("checked", "true");
					}
				}
			}
			else
			{
			   addFilterOptionMenuItem();
			}
			bIsFilterDataLoaded=true;
			if (loadingFilterMenu !=null)
				loadingFilterMenu._onDestroy=null;
			if (currentFilterMenu !=null)
			{
				currentFilterMenu._onDestroy=OnMouseOutFilter;
				OMenu(currentFilterMenu, filterTable, null, null, -1);
			}
		}
	}
}

function addSelection(row, clear, reposition)
{
	if(row==null)
		return;
	if(clear==true)
	{
		setSelectedColor(false);
		selected=new Array(0);
	}
	selected=selected.concat(new Array(row));
	setSelectedColor(true);
	if(reposition && row.focus)
	row.focus();
	PickerDialogUpdateAddSelectionButton();
}
function autoPostBackEnabled(elt)
{
  var autoPostBack=(elt==null)?null:elt.attributes.getNamedItem("AutoPostBack");
  return (autoPostBack!=null && autoPostBack.value=='1');
}
function schedulePostBack()
{
	window.setTimeout("__doPostBack('','')",0);
}
function saveOldEntities(elementId)
{
	var elt=document.getElementById(elementId);
	if(elt!=null&&autoPostBackEnabled(elt)) elt.oldEntities=getEntityKeysFromElement(elementId);
}
function postbackIfEntitiesChanged(elementId)
{
	var elt=document.getElementById(elementId);
	if (elt==null)
	{
		return false;
	}
	var oldKeys=elt.oldEntities;
	elt.oldEntities=null;
	var newKeys=getEntityKeysFromElement(elementId);
	var shouldPostBack=false;
	if(autoPostBackEnabled(elt))
	{
		if((oldKeys==null && newKeys!=null) || (oldKeys!=null && newKeys==null) || (oldKeys.length !=newKeys.length))
		{
			shouldPostBack=true;
		}
		else
		{
			for(i=0;!shouldPostBack&&i<oldKeys.length;i++)
			{
				if(oldKeys[i] !=newKeys[i])
				{
					shouldPostBack=true;
				}
			}
		}
	}
	if(shouldPostBack) schedulePostBack();
}
function getEntityKeysFromElement(elementId)
{
	var elt=document.getElementById(elementId);
	var keys=new Array();
	var i=0;
	for(x=0;elt!=null&&x<elt.childNodes.length;x++)
	{
		var child=elt.childNodes[x];
		if(child.attributes!=null)
		{
			var c=child.attributes.getNamedItem('class');
			if(c!=null&&c.value=='ms-entity-resolved')
			{
				var oDivEntityData=child.children('divEntityData');
				if (oDivEntityData !=null && oDivEntityData.getAttribute('key') !=null)
				{
					keys[i]=oDivEntityData.getAttribute('key');
					i++;
				}
			}
		}
	}
	return keys.sort();
}

function MSOWebPartPage_GetLocalizedStrings()
{
	var L_ResetPagePersonalizationDialog_TXT="You are about to reset all personalized Web Parts to their shared values and delete any private Web Parts. Click OK to complete this operation. Click Cancel to keep your personalized Web Part settings and private Web Parts.";
	var L_ResetPartPersonalizationDialog_TXT="Resetting this Web Part will cause you to lose any changes you made.  Are you sure you want to do this? To reset this Web Part, click OK. To keep your changes, click Cancel.";
	var L_RemoveConnection_TXT="Are you sure you want to remove the connection between the %0 Web Part and the %1 Web Part? To remove the connection, click OK. To keep the connection, click Cancel.";
	var L_ExportPersonalization_TXT="This Web Part Page has been personalized. As a result, one or more Web Part properties may contain confidential information. Make sure the properties contain information that is safe for others to read. After exporting this Web Part, view properties in the Web Part description file (.webpart or .dwp) by using a text editor, such as Microsoft Notepad.";
	var L_GetPropertiesFailure_ERR="Cannot retrieve properties at this time.";
	var L_SaveDirtyParts_TXT="Changes have been made to the contents of one or more Web Parts on this page. To save the changes, press OK.  To discard the changes, press Cancel.";
	var L_ToolPaneWidenToolTip_TXT="Widen";
	var L_ToolPaneShrinkToolTip_TXT="Narrow";
	var L_ToolPartExpandToolTip_TXT="Expand Toolpart: %0";
	var L_ToolPartCollapseToolTip_TXT="Collapse Toolpart: %0";
	var L_WebPartBackgroundColor_TXT="Web Part Background Color";
	var L_TransparentTooltip_TXT="Transparent Web Part Background Color";
	var L_InvalidURLPath_ERR="The URL is not valid for the %0 property. Check the URL spelling and path and try again.";
	var L_InvalidFolderPath_ERR="The path to the folder is not valid for the %0 property. Check the path name and try again.";
	var L_InvalidFilePath_ERR="The path to the file or folder is not valid. Check the path and try again.";
	var L_FileOrFolderUnsupported_ERR="The current browser does not support links to files or folders. To specify a link to a file or folder, you must use Microsoft Internet Explorer 5.0 or later";
	var L_Link_TXT="Link";
	var L_TransparentLiteral_TXT="Transparent";
	var L_ContentEditorSaveFailed_ERR="Cannot save your changes.";
	var L_AccessDenied_ERR="Access Denied saving Web Part properties: either the Web Part is embedded directly in the page, or you do not have sufficient permissions to save properties.";
	var L_NoInitArgs_ERR="Cannot create or modify the connection. One of the Web Parts does not have any data fields.";
	var s=new Object();
	s.ResetPagePersonalizationDialogText=L_ResetPagePersonalizationDialog_TXT;
	s.ResetPartPersonalizationDialogText=L_ResetPartPersonalizationDialog_TXT;
	s.RemoveConnection=L_RemoveConnection_TXT;
	s.ExportPersonalizationDialogText=L_ExportPersonalization_TXT;
	s.GetPropertiesFailure=L_GetPropertiesFailure_ERR;
	s.SaveDirtyPartsDialogText=L_SaveDirtyParts_TXT;
	s.ToolPaneWidenToolTip=L_ToolPaneWidenToolTip_TXT
	s.ToolPaneShrinkToolTip=L_ToolPaneShrinkToolTip_TXT;
	s.ToolPartExpandToolTip=L_ToolPartExpandToolTip_TXT;
	s.ToolPartCollapseToolTip=L_ToolPartCollapseToolTip_TXT;
	s.WebPartBackgroundColor=L_WebPartBackgroundColor_TXT;
	s.TransparentTooltip=L_TransparentTooltip_TXT;
	s.InvalidURLPath=L_InvalidURLPath_ERR;
	s.InvalidFolderPath=L_InvalidFolderPath_ERR;
	s.InvalidFilePath=L_InvalidFilePath_ERR;
	s.FileOrFolderUnsupported=L_FileOrFolderUnsupported_ERR;
	s.Link=L_Link_TXT;
	s.TransparentLiteral=L_TransparentLiteral_TXT;
	s.ContentEditorSaveFailed=L_ContentEditorSaveFailed_ERR;
	s.AccessDenied=L_AccessDenied_ERR;
	s.NoInitArgs=L_NoInitArgs_ERR;
	return s;
}
var MSOStrings=MSOWebPartPage_GetLocalizedStrings();
var L_AccessibleMenu_Text="Menu";
function FNEmpWz(wz)
{
	return (wz&&wz!="");
}
function AChld(p,c)
{    
	if(p&&c)p.appendChild(c);
}
function AImg(mi,wzISrc,wzIAlt)
{
	if(!mi)return;
	if(FNEmpWz(wzISrc))mi.setAttribute("iconSrc",wzISrc);
	if(FNEmpWz(wzIAlt))
		mi.setAttribute("iconAltText",wzIAlt);
	else
		mi.setAttribute("iconAltText","");
}
function CMenu(wzID)
{
	var m=document.getElementById(wzID);
	if (m)
	{
		m._initialized=false;
		m._oContents=null;
		m.innerHTML="";
		return m;
	}
	m=document.createElement("MENU");
	if(!m)return null;
	if(wzID)m.id=wzID;
	m.className="ms-SrvMenuUI";
	AChld(document.body,m);
	return m;
}
function CMItm(wzType)
{
	var mi=document.createElement("SPAN");
	if(!mi)return null;
	mi.setAttribute("type",wzType);
	return mi;
}
function SetInnerText(oNode, wzText)
{
	if (document.createTextNode !=null)
	{
		var parsedText=document.createTextNode(wzText);
		oNode.innerHTML="";
		oNode.appendChild( parsedText );
	}
	else
	{
		oNode.innerText=wzText;
	}
}
function CMOpt(wzText,wzAct,wzISrc,wzIAlt,wzISeq,wzDesc)
{
	var mo=CMItm("option");
	if(!mo)return null;
	mo.setAttribute("text", wzText);
	mo.setAttribute("onMenuClick", wzAct);
	if (wzDesc)mo.setAttribute("description", wzDesc);
	AImg(mo,wzISrc,wzIAlt);
	if(FNEmpWz(wzISeq))mo.setAttribute("sequence",wzISeq);
	return mo;
}
function CAMOpt(p,wzText,wzAct,wzISrc,wzIAlt,wzISeq,wzDesc)
{
	var mo=CMOpt(wzText,wzAct,wzISrc,wzIAlt,wzISeq,wzDesc);
	if(!mo)return null;
	AChld(p,mo);
	return mo;
}
function CIMOpt(p,wzText,wzAct,wzISrc,wzIAlt,wzISeq)
{
	var mo=CMOpt(wzText,wzAct,wzISrc,wzIAlt,wzISeq);
	if(!mo)return null;
	for (var i=0;i<p.childNodes.length;i++)
	{
		var iSeq=p.childNodes[i].getAttribute("sequence");
		if (iSeq)
		{
			if (iSeq > wzISeq)
			{
				p.childNodes[i].parentNode.insertBefore(mo, p.childNodes[i]);
				return mo;
			}
		}
	}
	AChld(p,mo);
	return mo;
}
function CMSep()
{
	var sep=CMItm("separator");
	SetInnerText(sep, "");
	return sep;
}
function CAMSep(p)
{
	var ms=CMSep();
	if(!ms)return null;
	AChld(p,ms);
	return ms;
}
function CSubM(wzText,wzISrc,wzIAlt,wzISeq,wzDesc)
{
	var sm=CMItm("submenu");
	if(!sm)return null;
	sm.setAttribute("text", wzText);
	if (wzDesc)sm.setAttribute("description", wzDesc);
	AImg(sm,wzISrc,wzIAlt);
	if(FNEmpWz(wzISeq))sm.setAttribute("sequence",wzISeq);
	return sm;
}
function CASubM(p,wzText,wzISrc,wzIAlt,wzISeq,wzDesc)
{
	var sm=CSubM(wzText,wzISrc,wzIAlt,wzISeq,wzDesc);
	if(!sm)return null;
	AChld(p,sm);
	return sm;
}
function FRdy(o)
{
	if (!o) return false;
	if (o.readyState==null)
		return true;
	switch (o.readyState)
		{
		case "loaded": case "interactive": case "complete": return true;
		default: return false;
		}
}
function OMenu(m,r,fr,ft,yoff)
{
	if(typeof(m)=="string")m=document.getElementById(m);
	if(m)
		{
			OMenuInt(m,r,fr,ft,yoff);
		}
	return false;
}
function OMenuInt(m,r,fr,ft,yoff)
{
	if(m&&!MenuHtc_isOpen(m)) MenuHtc_show(m,r,fr,ft,yoff);
}
function OMenuEvnt()
{
	var m=event.srcElement;
	if(m&&FRdy(document)&&FRdy(m))
		{
		var r=m.getAttribute("relativeTo");
		var fr=m.getAttribute("forceRefresh");
		var ft=m.getAttribute("flipTop");
		var yoff=m.getAttribute("yOffsetTop");
		if(r!=null)m.removeAttribute("relativeTo");
		if(fr!=null)m.removeAttribute("forceRefresh");
		if(ft!=null)m.removeAttribute("flipTop");
		if(yoff!=null)m.removeAttribute("yOffsetTop");
		m.onreadystatechange=null;
		OMenuInt(m,r,fr,ft,yoff);
		}
}
var kfnDisableEvent=new Function("return false");
var g_menuHtc_lastMenu=null;
var g_uniqueNumber=0;
function IsAccessibilityFeatureEnabledProxy()
{
	if (typeof(IsAccessibilityFeatureEnabled) !="undefined")
		return IsAccessibilityFeatureEnabled();
	return false;
}
function MenuHtc_show(oMaster, oParent, fForceRefresh, fFlipTop, yOffset)
{
	if (!(browseris.ie55up || browseris.nav6up || browseris.safari125up))
		return false;
	MenuHtc_hide();
	MenuHtc_init(oMaster);
	oMaster._oParent=oParent;
	oMaster._fIsRtL=IsElementRtl(oMaster._oParent);
	if ((browseris.ie || browseris.nav) && IsAccessibilityFeatureEnabledProxy())
	{
		var menu=null;
		if(oParent.foa !=null)
		{
			menu=byid(oParent.foa);			
			if(menu==null)
			{
				menu=eval(oParent.foa);	
			}
		}
		if (menu !=null && menu.onblur !=null)
		{
			menu.onblur();
		}
		RenderAccessibleMenu(oMaster, fForceRefresh);
		g_menuHtc_lastMenu=oMaster;
	}
	else
	{
		SetBodyEventHandlers(null);
		AssureId(oParent);
		var result=ShowRoot(oMaster, oParent, fForceRefresh, fFlipTop, yOffset);
		g_menuHtc_lastMenu=oMaster;
		NavigateToMenu(oMaster);
		SetBodyEventHandlers(HandleDocumentBodyClick);
	}
	if (browseris.ie)
	{
		if (window.event !=null)
			window.event.cancelBubble=true;
	}
	return false;
}
function MenuHtc_hide()
{
	ClearTimeOutToHideMenu();
	var oMaster=g_menuHtc_lastMenu;
	if (oMaster !=null)
	{
		if (oMaster._accessibleMenu !=null)
		{
			CloseAccessibleMenu(oMaster);
		}
		else
		{
			HideMenu(oMaster);
		}
	}
	g_menuHtc_lastMenu=null;
}
function MenuHtc_isOpen(oMaster)
{
	if (!oMaster || !oMaster._initialized)
		return false;
	var result=IsOpen(oMaster);
	return result;
}
function MenuHtc_item(oMaster, nLevel, nIndex)
{
	MenuHtc_init(oMaster);
	var result=GetItem(oMaster, nLevel, nIndex);
	return result;
}
function TrapMenuClick(e)
{
	if (e !=null)
		e.cancelBubble=true;
	return false;
}
function SetBodyEventHandlers(h)
{
	document.body.onclick=h;
}
function HandleDocumentBodyClick(e)
{
	if (g_menuHtc_lastMenu !=null)
	{
		var oMaster=g_menuHtc_lastMenu;
		if (oMaster !=null)
		{
			HideMenu(oMaster);
		}
	}
	return false;
}
function GetEventPopup(e)
{
	var obj=GetEventSrcElement(e);
	while (obj !=null)
	{
		if (obj.master !=null)
			return obj;
		obj=obj.parentNode;
	}
	return null;
}
function GetUniqueNumber()
{
	g_uniqueNumber++;
	return g_uniqueNumber;
}
function MenuHtc_init(oMaster)
{
	if (oMaster._initialized)
		return;
	oMaster._initialized=true;
	oMaster._wzPrefixID="mp"+GetUniqueNumber();
	if (oMaster.id==null)
		oMaster.id=oMaster._wzPrefixID+"_id";
	oMaster._nLevel=0;
	oMaster._arrPopup=new Array();
	oMaster._arrSelected=new Array();
	if (typeof(oMaster._onDestroy)=="undefined")
		oMaster._onDestroy=null;
	oMaster._fLargeIconMode=false;
	oMaster._fCompactItemsWithoutIcons=false;
}
function PrepContents(oMaster)
{
	oMaster._fLargeIconMode=(oMaster.getAttribute("largeIconMode")=="true");
	oMaster._fCompactItemsWithoutIcons=(oMaster.getAttribute("CompactMode")=="true");
	if (!browseris.safari)
	{
		oMaster._oContents=document.createElement("span");
		oMaster._oContents.style.display="none";
		oMaster._oContents.innerHTML=oMaster.innerHTML;
	}
	else
	{
		oMaster._oContents=oMaster.cloneNode(true);
		oMaster._oContents.style.display="none";
	}
	if (oMaster._fLargeIconMode)
	{
		if (oMaster._fIsRtL)
			oMaster._wzMenuStyle="ms-MenuUILargeRtL";
		else
			oMaster._wzMenuStyle="ms-MenuUILarge";
	}
	else
	{
		if (oMaster._fIsRtL)
			oMaster._wzMenuStyle="ms-MenuUIRtL";
		else
			oMaster._wzMenuStyle="ms-MenuUI";
	}
	oMaster._wzChkMrkPath="/_layouts/images/ChkMrk.gif";
	oMaster._wzMArrPath="/_layouts/images/MArr.gif";
	oMaster._wzMArrPathRtL="/_layouts/images/MArrRtL.gif";
}
function FixUpMenuStructure(oMaster)
{
	var menuNodes=oMaster._oRoot.childNodes;
	var lastGroupId=null;
	var lastMenuSeparatorRow=null;
	for (var nIndex=0; nIndex < menuNodes.length; nIndex++)
	{
		var menuRow=menuNodes[nIndex];
		if (menuRow.nodeType !=1)
			continue;
		var deleteRow=false;
		var displayNone=menuRow.style !=null && menuRow.style.display=='none';
		var jsHidden=FIsIHidden(menuRow);
		if (displayNone || jsHidden)
		{
			deleteRow=true;
		}
		else if (FIsIType(menuRow, "separator"))
		{
			if (lastMenuSeparatorRow !=null || nIndex==0)
				deleteRow=true;
			else
				lastMenuSeparatorRow=menuRow;
		}
		else
		{
			var cGroupId=menuRow.getAttribute("menuGroupId");
			if (cGroupId !=lastGroupId &&
				lastMenuSeparatorRow==null &&
				nIndex !=0)
			{
				var lastMenuSeparatorRow=document.createElement("ie:menuitem");
				lastMenuSeparatorRow.setAttribute("type","separator");
				oMaster._oRoot.insertBefore(lastMenuSeparatorRow,menuRow);
			}
			else if (FIsIType(menuRow, "submenu") && lastMenuSeparatorRow !=null)
			{
				menuRow.parentNode.removeChild(lastMenuSeparatorRow);
				lastMenuSeparatorRow=null;
			}
			else
			{
				lastMenuSeparatorRow=null;
			}
			lastGroupId=cGroupId;
		}
		if (deleteRow)
		{
			menuRow.parentNode.removeChild(menuRow);
			nIndex--;
		}
	}
	if(lastMenuSeparatorRow !=null)
		lastMenuSeparatorRow.parentNode.removeChild(lastMenuSeparatorRow);
}
function IsElementRtl(oCurrent)
{
	while (oCurrent !=null && oCurrent.tagName !=null)
	{
		var dir=oCurrent.getAttribute("dir");
		if ((dir==null || dir=="") && oCurrent.style !=null)
		{
			dir=oCurrent.style.direction;
		}
		if (dir=="rtl")
			return true;
		else if (dir=="ltr")
			return false;
		oCurrent=oCurrent.parentNode;
	}
	return false;
}
function AdjustScrollPosition(element, relativeToElement, result)
{
	var oCurrent=element;
	while (oCurrent !=null &&
		oCurrent !=relativeToElement &&
		oCurrent !=element.offsetParent &&
		oCurrent.tagName !=null &&
		oCurrent.tagName.toLowerCase() !="body" &&
		oCurrent.tagName.toLowerCase() !="html")
	{
		if (oCurrent.scrollWidth > oCurrent.clientWidth &&
			oCurrent.offsetWidth >=oCurrent.clientWidth &&
			oCurrent.clientWidth !=0)
		{
			if (!IsElementRtl(oCurrent))
			{
				if (oCurrent.scrollLeft > 0)
					result.x -=oCurrent.scrollLeft;
			}
			else
			{
				result.x+=(oCurrent.scrollWidth - oCurrent.offsetWidth - oCurrent.scrollLeft);
			}
		}
		if (oCurrent.scrollTop > 0)
			result.y -=oCurrent.scrollTop;
		oCurrent=oCurrent.parentNode;
	}
}
function MenuHtc_GetElementPosition(element, relativeToElement)
{
	var result=new Object();
	result.x=0;
	result.y=0;
	result.width=0;
	result.height=0;
	if (element.offsetParent) {
		var parent=element;
		while (parent !=null &&
			parent !=relativeToElement)
		{
			result.x+=parent.offsetLeft;
			result.y+=parent.offsetTop;
			AdjustScrollPosition(parent, relativeToElement, result);
			var parentTagName=parent.tagName.toLowerCase();
			if (parentTagName !="table" &&
				parentTagName !="body" &&
				parentTagName !="html" &&
				parentTagName !="div" &&
				parent.clientTop &&
				parent.clientLeft) {
				result.x+=parent.clientLeft;
				result.y+=parent.clientTop;
			}
			if (browseris.ie && parentTagName=="td")
			{
				if (parent.runtimeStyle.borderTopStyle !="none" ||
				    parent.currentStyle.borderTopStyle !="none")
				{
					var shift;
					if (parent.runtimeStyle.borderTopWidth !="")
					{
						shift=parseInt(parent.runtimeStyle.borderTopWidth);
					}
					else
					{
						shift=parseInt(parent.currentStyle.borderTopWidth);
					}
					if (!isNaN(shift))
					{
						result.y+=shift;
					}
				}
				if (parent.runtimeStyle.borderLeftStyle !="none" ||
				    parent.currentStyle.borderLeftStyle !="none")
				{
					var shift;
					if (parent.runtimeStyle.borderLeftWidth !="")
					{
						shift=parseInt(parent.runtimeStyle.borderLeftWidth);
					}
					else
					{
						shift=parseInt(parent.currentStyle.borderLeftWidth);
					}
					if (!isNaN(shift))
					{
						result.x+=shift;
					}
				}
			}
			parent=parent.offsetParent;
		}
	}
	else if (element.left && element.top) {
		result.x=element.left;
		result.y=element.top;
	}
	else {
		if (element.x) {
			result.x=element.x;
		}
		if (element.y) {
			result.y=element.y;
		}
	}
	if (element.offsetWidth && element.offsetHeight) {
		result.width=element.offsetWidth;
		result.height=element.offsetHeight;
	}
	else if (element.style && element.style.pixelWidth && element.style.pixelHeight) {
		result.width=element.style.pixelWidth;
		result.height=element.style.pixelHeight;
	}
	return result;
}
function MenuHtcInternal_Show(oMaster, oParent, y, fFlipTop)
{
	var oPopup=oMaster._arrPopup[oMaster._nLevel];	
	var nIndex;							
	var fTopLevel;							
	var oInnerDiv;
	if (!oMaster._oContents) PrepContents(oMaster);
	if (!oMaster._oContents || IsOpen(oMaster)) return;
	if (!oPopup && !oMaster._oRoot)
		{
		oMaster._nLevel=0;
		oMaster._oRoot=oMaster._oContents;
		}
	fTopLevel=oMaster._nLevel==0;
	fFlipTop=fFlipTop && fTopLevel;
	if (!oPopup)
	{
		oMaster._arrPopup[oMaster._nLevel]=document.createElement("DIV");
		oPopup=oMaster._arrPopup[oMaster._nLevel];
		oPopup.isMenu=true;
		oPopup.master=oMaster;
		oPopup.level=oMaster._nLevel;
		oInnerDiv=document.createElement("DIV");
		var oTable=document.createElement("table");
		var oTBody=document.createElement("tbody");
		oInnerDiv.isInner=true;
		oPopup.style.position="absolute";
		oInnerDiv.style.overflow="visible";
		oTable.appendChild(oTBody);
		oInnerDiv.appendChild(oTable);
		oPopup.appendChild(oInnerDiv);
		if (oMaster._fIsRtL)
			oPopup.setAttribute("dir", "rtl");
		else
			oPopup.setAttribute("dir", "ltr");
		document.body.appendChild(oPopup);
		FixUpMenuStructure(oMaster);
		var id=0;
		var childNodeLength=oMaster._oRoot.childNodes.length;
		for (nIndex=0; nIndex < childNodeLength; nIndex++)
		{
			var oNode=oMaster._oRoot.childNodes[nIndex];
			if (oNode.nodeType !=1)
				continue;
			if (!FIsIType(oNode, "label"))
			{
				var oItem=CreateMenuItem(oMaster, oNode, MakeID(oMaster, oMaster._nLevel, id));
				if (oItem) oTBody.appendChild(oItem);
				id++;
			}
		}
		oPopup.className="ms-MenuUIPopupBody";
		oTable.className=oMaster._wzMenuStyle;
		oTable.cellSpacing=0;
		oTable.cellPadding=0;
		oPopup.oncontextmenu=kfnDisableEvent;
		oPopup.ondragstart=kfnDisableEvent;
		oPopup.onselectstart=kfnDisableEvent;
		if (oParent._onmouseover==null)
			oParent._onmouseover=oParent.onmouseover;
		if (oParent._onmouseout==null)
			oParent._onmouseout=oParent.onmouseout;
		if (oParent._onmousedown==null)
			oParent._onmousedown=oParent.onmousedown;
		if (oParent._onclick==null)
			oParent._onclick=oParent.onclick;
		if (browseris.nav)
		{
			oPopup.onkeypress=function(e) {return false; };
			oPopup.onkeyup=function(e) {return false; };
			oPopup.onkeydown=function(e) {PopupKeyDown(e); return false; };
			oPopup.onmousedown=function(e) {TrapMenuClick(e); return false; };
			oPopup.onmouseover=function(e) {PopupMouseOver(e); return false; };
			oPopup.onmouseout=function(e) {PopupMouseLeave(e); return false; };
			oPopup.onclick=function(e) {PopupMouseClick(e); TrapMenuClick(e); return false; };
			oParent.onmouseover=function (e) {PopupMouseOverParent(e); return false; };
			oParent.onmouseout=function(e) {PopupMouseLeaveParent(e); return false; };
			oParent.onmousedown=function(e) {TrapMenuClick(e); return false; };
			oParent.onclick=function(e) {TrapMenuClick(e); return false; };
			oParent.oncontextmenu=function(e) {TrapMenuClick(e); return false; };
		}
		else
		{
			oPopup.onkeydown=new Function("PopupKeyDown(event); return false;");
			oPopup.onmousedown=new Function("TrapMenuClick(event); return false;");
			oPopup.onmouseover=new Function("PopupMouseOver(event); return false;");
			oPopup.onmouseout=new Function("PopupMouseLeave(event); return false;");
			oPopup.onclick=new Function("PopupMouseClick(event); TrapMenuClick(event); return false;");
			oParent.onmouseover=new Function("PopupMouseOverParent(event); return false;");
			oParent.onmouseout=new Function("PopupMouseLeaveParent(event); return false;");
			oParent.onmousedown=new Function("TrapMenuClick(event); return false;");
			oParent.onclick=new Function("TrapMenuClick(event); return false;");
			oParent.oncontextmenu=new Function("TrapMenuClick(event); return false;");
		}
		if (fTopLevel)
		{
			var wzOnUnload=oMaster.getAttribute("onunloadtext");
			if (wzOnUnload) oPopup.onunload=new Function(wzOnUnload);
		}
	}
	else
	{
		var oOld=oMaster._arrSelected[oMaster._nLevel];
		if (oOld) UnselectItem(oOld);
	}
	oMaster._arrSelected[oMaster._nLevel]=null;
	var oBackFrame;
	if (browseris.ie)
	{
		var originalScrollLeft=document.body.scrollLeft;
		oBackFrame=document.createElement("iframe");
		AssureId(oBackFrame);
		oBackFrame.src="/_layouts/blank.htm";
		oBackFrame.style.position="absolute";
		oBackFrame.style.display="none";
		oBackFrame.scrolling="no";
		oBackFrame.frameBorder="0";
		document.body.appendChild(oBackFrame);
		oPopup.style.zIndex=103;
		oPopup._backgroundFrameId=oBackFrame.id;
		if (originalScrollLeft !=document.body.scrollLeft)
		{
			document.body.scrollLeft=originalScrollLeft;
		}
	}
	SetMenuPosition(oMaster, oParent, oPopup, oInnerDiv, fFlipTop, fTopLevel);
	if (browseris.ie)
	{
		SetBackFrameSize(null, oPopup);
		oPopup.onresize=new Function("SetBackFrameSize(event, null);");
		oBackFrame.style.display="block";
		oBackFrame.style.zIndex=101;
	}
}
function SetMenuPosition(oMaster, oParent, oPopup, oInnerDiv, fFlipTop, fTopLevel)
{
	var maxWidth=window.screen.width;
	var maxHeight=window.screen.height;
	if (browseris.nav)
	{
		maxWidth=document.body.clientWidth;
		maxHeight=document.body.clientHeight;
	}
	else if (self.innerHeight)
	{
		maxWidth=self.innerWidth;
		maxHeight=self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
	{
		maxWidth=document.documentElement.clientWidth;
		maxHeight=document.documentElement.clientHeight;
	}
	else if (document.body)
	{
		maxWidth=document.body.clientWidth;
		maxHeight=document.body.clientHeight;
	}
	var nRealWidth=oPopup.scrollWidth+oPopup.offsetWidth - oPopup.clientWidth;
	var nRealHeight=oPopup.scrollHeight+oPopup.offsetHeight - oPopup.clientHeight;
	var widthTooBig=false;
	var heightTooBig=false;
	if (nRealWidth > maxWidth - 50)
	{
		widthTooBig=true;
		nRealWidth=maxWidth - 50;
	}
	if (oMaster._fCompactItemsWithoutIcons && nRealHeight >=375)
	{
		heightTooBig=true;
		nRealHeight=375;
	}
	if (nRealHeight >=maxHeight - 50)
	{
		heightTooBig=true;
		nRealHeight=maxHeight - 50;
	}
	if (!widthTooBig && !heightTooBig)
	{
		oInnerDiv.style.overflow="visible";
	}
	else
	{
		if (browseris.ie)
		{
			if (widthTooBig)
			{
				oPopup.style.width=nRealWidth+"px";
				oInnerDiv.style.width=nRealWidth+"px";
				oInnerDiv.style.overflowX="scroll";
			}
			else
			{
				oInnerDiv.style.width=nRealWidth+"px";
				oInnerDiv.style.overflowX="visible";
			}
			if (heightTooBig)
			{
				oPopup.style.height=nRealHeight+"px";
				oInnerDiv.style.height=nRealHeight+"px";
				oInnerDiv.style.overflowY="scroll";
			}
			else
			{
				oInnerDiv.style.height=nRealHeight+"px";
				oInnerDiv.style.overflowY="visible";
			}
		}
		else
		{
			oPopup.style.height=nRealHeight+"px";
			oInnerDiv.style.height=nRealHeight+"px";
			oPopup.style.width=nRealWidth+"px";
			oInnerDiv.style.width=nRealWidth+"px";
			oInnerDiv.style.overflow="auto";
		}
	}
	nRealWidth=oPopup.scrollWidth+oPopup.offsetWidth - oPopup.clientWidth;
	nRealHeight=oPopup.scrollHeight+oPopup.offsetHeight - oPopup.clientHeight;
	var EdgeLeft=0;
	var EdgeRight=maxWidth;
	var ParentLeft=0;
	var EdgeTop=0;
	var ParentTop=0;
	var oCurrent=oParent;
	if (browseris.safari)
	{
		if (oCurrent.tagName=="TR" && oCurrent.childNodes.length > 0)
			oCurrent=oCurrent.childNodes[0];
	}
	var p=MenuHtc_GetElementPosition(oCurrent);
	ParentLeft=p.x;
	ParentTop=p.y;
	var nParentWidth;
	if (fTopLevel)
	{
		nParentWidth=p.width;
		ParentTop+=p.height;
		ParentTop -=1;
	}
	else
	{
		nParentWidth=p.width+1;
	}
	var fTryGoDefault=!fFlipTop && !document.body.getAttribute("flipped");
	var fFlippedDefault, fFlippedNonDefault;
	var xDefault, xFlipped;
	if (!oMaster._fIsRtL)
	{
		var MenuRightDefault;
		var MenuLeftFlipped;
		if (fTopLevel)
		{
			xDefault=ParentLeft;
			MenuRightDefault=ParentLeft+nRealWidth;
			MenuLeftFlipped=ParentLeft+nParentWidth - nRealWidth;
		}
		else
		{
			xDefault=ParentLeft+nParentWidth;
			MenuRightDefault=ParentLeft+nParentWidth+nRealWidth;
			MenuLeftFlipped=ParentLeft - nRealWidth;
		}
		xFlipped=MenuLeftFlipped;
		fFlippedDefault=MenuRightDefault > EdgeRight && MenuLeftFlipped > EdgeLeft;
		fFlippedNonDefault=!(MenuLeftFlipped < EdgeLeft && MenuRightDefault < EdgeRight);
	}
	else
	{
		var MenuLeftDefault;
		var MenuRightFlipped;
		if (fTopLevel)
		{
			MenuLeftDefault=ParentLeft+nParentWidth - nRealWidth;
			MenuRightFlipped=ParentLeft+nRealWidth;
			xFlipped=ParentLeft;
		}
		else
		{
			MenuLeftDefault=ParentLeft - nRealWidth;
			MenuRightFlipped=ParentLeft+nParentWidth+nRealWidth;
			xFlipped=ParentLeft+nParentWidth;
		}
		xDefault=MenuLeftDefault;
		fFlippedDefault=MenuLeftDefault < EdgeLeft && MenuRightFlipped < EdgeRight;
		fFlippedNonDefault=!(MenuRightFlipped > EdgeRight && MenuLeftDefault > EdgeLeft);
	}
	var fFlipped=fTryGoDefault ? fFlippedDefault : fFlippedNonDefault;
	var x=fFlipped ? xFlipped : xDefault;
	var xOffset;
	var yOffset;
	if (browseris.nav)
	{
		xOffset=window.pageXOffset;
		yOffset=window.pageYOffset;
	}
	else
	{
		var htmlElement=document.body.parentElement;
		if (!IsElementRtl(document.body))
		{
			xOffset=document.body.scrollLeft;
			xOffset+=htmlElement.scrollLeft;
		}
		else
		{
			xOffset=-document.body.scrollWidth+document.body.offsetWidth+document.body.scrollLeft;
			xOffset+=-htmlElement.scrollWidth+htmlElement.offsetWidth+htmlElement.scrollLeft;
		}
		yOffset=document.body.scrollTop;
		yOffset+=htmlElement.scrollTop;
	}
	if (nRealWidth >=maxWidth)
	{
		x=xOffset;
	}
	else if (x - xOffset+nRealWidth >=maxWidth)
	{
		x=xOffset+maxWidth - nRealWidth;
	}
	var y;
	if (nRealHeight >=maxHeight)
	{
		y=yOffset;
	}
	else if (ParentTop+nRealHeight - yOffset >=maxHeight)
	{
		y=yOffset+maxHeight - nRealHeight;
	}
	else
	{
		y=ParentTop;
	}
	oPopup.setAttribute("flipped", fFlipTop ? fFlipped && fFlippedDefault : fFlipped);
	var posLeft=Math.max(x,xOffset);
	var posTop=Math.max(y,yOffset);
	oPopup.style.left=posLeft+"px";
	oPopup.style.top=posTop+"px";
}
function SetBackFrameSize(e, oPopup)
{
	if (oPopup==null)
		oPopup=GetEventSrcElement(e);
	var nRealWidth=oPopup.scrollWidth+oPopup.offsetWidth - oPopup.clientWidth;
	var nRealHeight=oPopup.scrollHeight+oPopup.offsetHeight - oPopup.clientHeight;
	var oBackFrame=document.getElementById(oPopup._backgroundFrameId);
	oBackFrame.style.left=oPopup.offsetLeft+"px";
	oBackFrame.style.top=oPopup.offsetTop+"px";
	oBackFrame.style.width=nRealWidth+"px";
	oBackFrame.style.height=nRealHeight+"px";
}
function HideMenu(oMaster, nPhase)
{
	ClearTimeOutToHideMenu();
	if (nPhase==null)
		nPhase=0;
	if (nPhase==2)
	{
		if (oMaster._onDestroy !=null)
		{
			oMaster._onDestroy();
			oMaster._onDestroy=null;
		}
		return;
	}
	if (IsOpen(oMaster) && !IsAccessibilityFeatureEnabledProxy())
	{
		if (oMaster._oParent !=null)
		{
			oMaster._oParent.onclick=oMaster._oParent._onclick;
			oMaster._oParent.onmouseover=oMaster._oParent._onmouseover;
			oMaster._oParent.onmouseout=oMaster._oParent._onmouseout;
			oMaster._oParent.onmousedown=oMaster._oParent._onmousedown;
		}
		SetBodyEventHandlers(null);
		UpdateLevel(oMaster, 0);
		var oPopup=oMaster._arrPopup[0];
		if (oPopup !=null)
		{
			var oBackFrame=document.getElementById(oPopup._backgroundFrameId);
			if (oBackFrame !=null)
				oBackFrame.parentNode.removeChild(oBackFrame);
			oPopup.parentNode.removeChild(oPopup);
			oMaster._arrPopup[0]=null;
			if (nPhase==0)
			{
				if (oMaster._onDestroy !=null)
				{
					oMaster._onDestroy();
					oMaster._onDestroy=null;
				}
			}
		}
		g_menuHtc_lastMenu=null;
	}
}
function IsOpen(oMaster)
{
	if (oMaster._accessibleMenu && !oMaster._accessibleMenu.closed)
		return true;
	if (!oMaster._arrPopup)
		return false;
	var oPopup=oMaster._arrPopup[oMaster._nLevel];
	return oPopup;
}
function FindLabel(oParent)
{
	var arrNodes=oParent ? oParent.childNodes : null;
	if (arrNodes)
		{
		for (var nIndex=0; nIndex < arrNodes.length; nIndex++)
			{
			var oNode=arrNodes[nIndex];
			if (oNode.nodeType !=1)
				continue;
			if (FIsIType(oNode, "label")) return oNode;
			}
		}
	return null;
}
function ShowRoot(oMaster, oParent, fForceRefresh, fFlipTop, yOffset)
{
	UpdateLevel(oMaster, 0);
	if (fForceRefresh)
		{
		oMaster._oContents=null;
		oMaster._oRoot=null;
		oMaster._nLevel=0;
		oMaster._arrPopup=new Array();
		oMaster._arrSelected=new Array();
		}
	else
		{
		oMaster._oRoot=oMaster._oContents;
		}
	var y=0;
	if (oParent) y+=oParent.offsetHeight;
	if (browseris.safari)
	{
		if (oParent.tagName=="TR" && oParent.childNodes.length > 0)
		{
			y+=(oParent.childNodes[0].offsetTop+oParent.childNodes[0].offsetHeight
				- oParent.offsetTop);
		}
	}
	if (yOffset) y+=yOffset;
	fFlipTop=fFlipTop !=false;
	MenuHtcInternal_Show(oMaster, oParent, y, fFlipTop);
}
function ShowSubMenu(oMaster, nLevel, oParent)
{
	if (!oParent) return;
	if (oParent.submenuRoot==null) return;
	UpdateLevel(oMaster, nLevel);
	oMaster._oRoot=oParent.submenuRoot;
	oMaster._nLevel=oMaster._nLevel+1;
	MenuHtcInternal_Show(oMaster, oParent, -1);
}
function ShowSubMenuEvnt(id)
{
	var oMaster=document.getElementById(id);
	var oPopup=oMaster._arrPopup[oMaster._nLevel];
	if (oPopup)
		{
		oPopup.removeAttribute("timeoutID");
		ShowSubMenu(oMaster, oMaster._nLevel, oMaster._arrSelected[oMaster._nLevel]);
		}
}
function SetShowSubMenuEvnt(oMaster)
{
	var oPopup=oMaster._arrPopup[oMaster._nLevel];
	if (oPopup)
	{
		ClearTimeOut("timeoutID");
		document.body.setAttribute("timeoutID", window.setTimeout(new Function("ShowSubMenuEvnt('"+oMaster.id+"');"), 100));
	}
}
function ClearTimeOut(oAttribute)
{
	var id=document.body.getAttribute(oAttribute);
	if (id !=null)
	{
		window.clearTimeout(id);
	}
	document.body.removeAttribute(oAttribute);
}
function ClearShowSubMenuEvnt(oPopup)
{
	ClearTimeOut("timeoutID");
}
function GetEventSrcItem(oMaster, srcElement)
{
	for (var oSrc=srcElement;
		oSrc && !FIStringEquals(oSrc.tagName, "BODY");
		oSrc=oSrc.parentNode)
	{
		if (FIStringEquals(oSrc.tagName, "TR") &&
			oSrc.id.substring(0, oMaster._wzPrefixID.length)==oMaster._wzPrefixID)
		{
			return oSrc;
		}
	}
	return null;
}
function UpdateLevel(oMaster, nLevel)
{
	var oPopup;
	while (oMaster._nLevel > nLevel)
		{
		oPopup=oMaster._arrPopup[oMaster._nLevel];
		if (oPopup)
			{
			ClearShowSubMenuEvnt(oPopup);
			var oBackFrame=document.getElementById(oPopup._backgroundFrameId);
			if (oBackFrame !=null)
				oBackFrame.parentNode.removeChild(oBackFrame);
			oPopup.parentNode.removeChild(oPopup);
			}
		oMaster._arrPopup[oMaster._nLevel]=null;
		oMaster._arrSelected[oMaster._nLevel]=null;
		oMaster._oRoot=oMaster._oRoot.parentNode;
		oMaster._nLevel--;
		}
	oPopup=oMaster._arrPopup[oMaster._nLevel];
	if (oPopup) ClearShowSubMenuEvnt(oPopup);
}
function PopupMouseOver(e)
{
	var oPopup=GetEventPopup(e);
	if (oPopup !=null)
	{
		var oMaster=oPopup.master;
		var nLevel=oPopup.level;
		if (nLevel < 0) return;
		var oSrcElem=GetEventSrcItem(oMaster, GetEventSrcElement(e));
		if (oSrcElem)
		{
			if (oSrcElem !=oMaster._arrSelected[nLevel])
			{
				if (FIsIType(oSrcElem, "separator"))
					return;
				ToggleMenuItem(oMaster, nLevel, oSrcElem);
				if (FIsIType(oSrcElem, "submenu"))
					EngageSelection(oMaster, true, true, false);
			}
			else if (nLevel < oMaster._nLevel)
			{
				UnselectCurrentOption(oMaster);
			}
		}
		ClearTimeOutToHideMenu();
	}
}
function PopupMouseLeave(e)
{
	var oPopup;
	oPopup=GetEventPopup(e);
	if (oPopup !=null)
	{
		UnselectCurrentOption(oPopup.master);
		SetTimeOutToHideMenu();
	}
	return false;
}
function PopupMouseOverParent(e)
{
	if (g_menuHtc_lastMenu !=null)
	{
		ClearTimeOutToHideMenu();
		if (g_menuHtc_lastMenu._oParent !=null && g_menuHtc_lastMenu._oParent._onmouseover !=null)
		{
			g_menuHtc_lastMenu._oParent._onmouseover();
		}
	}
}
function PopupMouseLeaveParent(e)
{
	if (g_menuHtc_lastMenu !=null)
	{
		if (g_menuHtc_lastMenu._oParent !=null && g_menuHtc_lastMenu._oParent._onmouseout !=null)
		{
				g_menuHtc_lastMenu._oParent._onmouseout();
		}		
		SetTimeOutToHideMenu();		
	}
}
function ClearTimeOutToHideMenu()
{
	if (document.body.getAttribute("HideMenuTimeOut") !=null)
	{
		ClearTimeOut("HideMenuTimeOut");
	}
}
function SetTimeOutToHideMenu()
{
	ClearTimeOut("HideMenuTimeOut");
	document.body.setAttribute("HideMenuTimeOut", window.setTimeout(MenuHtc_hide, 1500));
}
function PopupMouseClick(e)
{
	var oPopup=GetEventPopup(e);
	var oMaster=oPopup.master;
	var nLevel=oPopup.level;
	if (nLevel < 0) return;
	var oItem=oMaster._arrSelected[nLevel];
	UpdateLevel(oMaster, nLevel);
	EngageSelection(oMaster, true, false, false);
}
function PopupKeyDown(e)
{
	var oPopup=GetEventPopup(e);
	var oMaster=oPopup.master;
	var nLevel=oPopup.level;
	if (nLevel < 0)
		return;
	var nKeyCode=GetEventKeyCode(e);
	var shiftKey=e.shiftKey;
	if (oMaster._fIsRtL)
		{
		if (nKeyCode==37) nKeyCode=39;
		else if (nKeyCode==39) nKeyCode=37;
		}
	if (nKeyCode==9) nKeyCode=!shiftKey ? 40 : 38;
	ClearShowSubMenuEvnt(oPopup);
	switch (nKeyCode)
		{
	case 38:	
		MoveMenuSelection(oMaster, -1);
		break;
	case 40:	
		MoveMenuSelection(oMaster, 1);
		break;
	case 37:	
	case 27:	
		CloseCurrentLevel(oMaster, nKeyCode==27);
		break;
	case 39:	
	case 13:	
		EngageSelection(oMaster, nKeyCode==13, false, true);
		break;
		}
	e.returnValue=false;
}
function SetNewId(obj)
{
	obj.id="msomenuid"+GetUniqueNumber();
	return obj.id;
}
function AssureId(obj)
{
	if (obj.id==null || obj.id=="")
		obj.id="msomenuid"+GetUniqueNumber();
	return obj.id;
}
function NavigateToMenu(oMaster)
{
	var oMenu=oMaster._arrPopup[oMaster._nLevel].firstChild;
	AssureId(oMenu);
	try
	{		
		var oFirstItem=oMenu.firstChild.firstChild.firstChild;		
		oFirstItem.tabIndex=0;
		if (oFirstItem.setActive !=null)
			oFirstItem.setActive();
		else if (oFirstItem.focus !=null)
			oFirstItem.focus();
	}
	catch (e)
	{
	}
}
function ExecuteOnClick(fnOnClick)
{
	try
	{
		if (browseris.safari)
		{
			if (FIStringEquals(typeof(fnOnClick), "string"))
				eval("var document=window.document; {"+fnOnClick+"}");
			else
				fnOnClick();
		}
		else
		{
			if (FIStringEquals(typeof(fnOnClick), "string"))
			{
				fnOnClick=new Function("var document=window.document; {"+fnOnClick+"}");
			}
			var oTemp=window.document.body.appendChild(window.document.createElement("span"));
			oTemp.onclick=fnOnClick;
			oTemp.onclick();
			oTemp.parentNode.removeChild(oTemp);
		}
	}
	catch (e)
	{
	}
}
function EngageSelection(oMaster, fDoSelection, fDelayExpandSM, fEnterSM)
{
	var oItem=oMaster._arrSelected[oMaster._nLevel];
	if (!oItem || oItem.optionDisabled) return;
	if (FIsIType(oItem, "submenu"))
	{
		if (fDelayExpandSM)
		{
			SetShowSubMenuEvnt(oMaster);
		}
		else
		{
			ShowSubMenu(oMaster, oMaster._nLevel, oItem);
			if (fEnterSM) MoveMenuSelection(oMaster, 1);
		}
	}
	else if (fDoSelection)
	{
		var fEnabled=oItem.getAttribute("enabled");
		if (fEnabled !="false")
		{
			var fnOnClick=oItem.getAttribute("onMenuClick");
			if (fnOnClick)
			{
				HideMenu(oMaster, 1);
				ExecuteOnClick(fnOnClick);
				HideMenu(oMaster, 2);
			}
		}
	}
}
function CloseCurrentLevel(oMaster, fAllowHideRoot)
{
	if (oMaster._nLevel > 0)
	{
		UpdateLevel(oMaster, oMaster._nLevel - 1);
		var obj=oMaster._arrSelected[oMaster._nLevel];
		if (obj !=null)
		{
			if (browseris.nav)
			{
				obj=obj.firstChild.firstChild.firstChild.firstChild.firstChild.nextSibling.firstChild.firstChild;
				if (obj.focus !=null)
					obj.focus();
			}
			else
			{
				if (obj.focus !=null)
					obj.focus();
			}
		}
	}
	else if (fAllowHideRoot)
	{
		HideMenu(oMaster);
		var oParent=oMaster._oParent;
		while (oParent !=null &&
			oParent.tagName=="SPAN" &&
			oParent.getAttribute("contentEditable") !=null)
		{
			oParent=oParent.parentElement;
		}
		if (oParent !=null)
		{
			var focusElement=oParent;
			if (oParent.foa !=null)
			{
				var foa=null;
				foa=eval(oParent.foa);
				if(foa==null)
				{
					foa=byid(oParent.foa );
				}
				if (foa !=null)
				{
					focusElement=foa;
				}
			}
			if (focusElement.setActive !=null)
			{
				focusElement.setActive();
			}
			else if (focusElement.focus !=null)
			{
				focusElement.focus();
			}
		}
	}
}
function UnselectCurrentOption(oMaster)
{
	if (oMaster._nLevel >=0)
		{
		var oItem=oMaster._arrSelected[oMaster._nLevel];
		if (FIsIType(oItem, "option"))
			{
			UnselectItem(oItem);
			oMaster._arrSelected[oMaster._nLevel]=null;
			}
		}
}
function MakeID(oMaster, nLevel, nIndex)
{
	return oMaster._wzPrefixID+"_"+nLevel+"_"+nIndex;
}
function GetItem(oMaster, nLevel, nIndex)
{
	var oPopup=oMaster._arrPopup[nLevel];
	return oPopup ? document.getElementById(MakeID(oMaster, nLevel, nIndex)) : null;
}
function MoveMenuSelection(oMaster, iDir)
{
	var nIndex=-1;
	var nNumItems=oMaster._oRoot.childNodes.length;
	var oSelected=oMaster._arrSelected[oMaster._nLevel];
	if (oSelected)
	{
		var wzSelectedID=oSelected ? oSelected.id : null;
		if (wzSelectedID)
		{
			var nCurIndex=parseInt(wzSelectedID.substring(wzSelectedID.lastIndexOf("_")+1, wzSelectedID.length));
			nIndex=(nCurIndex+nNumItems+iDir) % nNumItems;
		}
	}
	if (nIndex < 0)
		nIndex=iDir > 0 ? 0 : (nNumItems - 1);
	var oItem;
	var nIndexStart=nIndex;
	do
	{
		oItem=GetItem(oMaster, oMaster._nLevel, nIndex);
		nIndex=(nIndex+nNumItems+iDir) % nNumItems;
	}
	while (nIndex !=nIndexStart &&
			 (!oItem || oItem.style.display=="none" ||
			  !(FIsIType(oItem, "option") || FIsIType(oItem, "submenu"))));
	ToggleMenuItem(oMaster, oMaster._nLevel, oItem);
}
function ToggleMenuItem(oMaster, nLevel, oItem)
{
	var oOld=oMaster._arrSelected[nLevel];
	if (!oItem || (oOld && oItem.id==oOld.id)) return;
	if (oOld)
	{
		UnselectItem(oOld);
		oOld.onkeydown=null;
		oOld.onmousedown=null;
		oOld.onmouseover=null;
		oOld.onmouseout=null;
		oOld.oncontextmenu=null;
	}
	UpdateLevel(oMaster, nLevel);
	SelectItem(oItem);
	oMaster._arrSelected[nLevel]=oItem;
	oItem.tabIndex=0;
	if (oItem.setActive !=null)
		oItem.setActive();
	else if (oItem.focus !=null)
		oItem.focus();
	var oPopup=oMaster._arrPopup[nLevel];
	var oDiv=oPopup.childNodes[0];
	var posPopup=MenuHtc_GetElementPosition(oItem, oDiv);
	if (posPopup.y+posPopup.height - oDiv.scrollTop > oDiv.offsetHeight)
	{
		oDiv.scrollTop=posPopup.y+posPopup.height - oDiv.offsetHeight;
	}
	else if (posPopup.y < oDiv.scrollTop)
	{
		oDiv.scrollTop=posPopup.y;
	}
}
function SelectItem(oItem)
{
	if (!oItem) return;
	var oItemTableCell=oItem.firstChild;
	var oItemTable=oItemTableCell.firstChild;
	if (oItemTableCell.className=="ms-MenuUIItemTableCellCompact")
		oItemTableCell.className="ms-MenuUIItemTableCellCompactHover";	
	else
		oItemTableCell.className="ms-MenuUIItemTableCellHover";
	oItemTable.className="ms-MenuUIItemTableHover";
}
function UnselectItem(oItem)
{
	if (!oItem) return;
	var oItemTableCell=oItem.firstChild;
	var oItemTable=oItemTableCell.firstChild;
	if (oItemTableCell.className=="ms-MenuUIItemTableCellCompactHover")
		oItemTableCell.className="ms-MenuUIItemTableCellCompact";	
	else
		oItemTableCell.className="ms-MenuUIItemTableCell";
	oItemTable.className="ms-MenuUIItemTable";
}
function SetImageSize(oMaster, oImg, oSize)
{
	if (oSize==null)
	{
		if (oMaster._fLargeIconMode)
			oSize=32;
		else
			oSize=16;
	}
	oImg.width=oSize;
	oImg.height=oSize;
}
function CreateMenuOption(oMaster, oRow, oNode, wzID, wzHtml)
{
	var oIcon=document.createElement("td");
	var oLabel=document.createElement("td");
	var oAccKey=document.createElement("td");
	var oArrow=document.createElement("td");
	oRow.appendChild(oIcon);
	oRow.appendChild(oLabel);
	oRow.appendChild(oAccKey);
	oRow.appendChild(oArrow);
	if (oMaster._fLargeIconMode)
		oIcon.className=!oMaster._fIsRtL ? "ms-MenuUIIconLarge" : "ms-MenuUIIconRtlLarge";
	else
		oIcon.className=!oMaster._fIsRtL ? "ms-MenuUIIcon" : "ms-MenuUIIconRtL";
	oIcon.align="center";
	if (oMaster._fCompactItemsWithoutIcons && !oNode.getAttribute("iconSrc"))
		oLabel.className=!oMaster._fIsRtL ? "ms-MenuUILabelCompact" : "ms-MenuUILabelCompactRtl";
	else
		oLabel.className=!oMaster._fIsRtL ? "ms-MenuUILabel" : "ms-MenuUILabelRtL";
	oAccKey.className="ms-MenuUIAccessKey";
	oArrow.className="ms-MenuUISubmenuArrow";
	if (!oMaster._fLargeIconMode)
	{
		oLabel.noWrap=true;
	}
	oIcon.noWrap=true;
	oAccKey.noWrap=true;
	oArrow.noWrap=true;
	oLabel.id=oNode.id;
	if (!wzHtml) wzHtml=oNode.innerHTML;
	if (oNode.getAttribute("enabled")=="false")
	{
		oRow.disabled=true;
		oLabel.className+=" ms-MenuUIItemTableCellDisabled";
	}
	var wzIconSrc=null, wzIconAlt=null;
	if (oNode.getAttribute("checked")=="true")
		{
		wzIconSrc=oMaster._wzChkMrkPath;
		wzIconAlt="*";
		}
	else
		{
		wzIconSrc=EvalAttributeValue(oNode, "iconSrc", "iconScript");
		wzIconAlt=oNode.getAttribute("iconAltText");
		}
	var innerHtml=wzHtml;
	var sText=EvalAttributeValue(oNode, "text", "textScript");
	var sDescription=EvalAttributeValue(oNode, "description", "descriptionScript");
	var oMenuItemBody=document.createElement("div");
	if (sDescription !=null && oMaster._fLargeIconMode)
	{
		var oBold=document.createElement("B");
		var oTextSpan=document.createElement("SPAN");
		var oTextNode=document.createTextNode(sText);
		var oBr=document.createElement("BR");
		var oDescSpan=document.createElement("SPAN");
		var oDescNode=document.createTextNode(sDescription);
		oTextSpan.setAttribute("style","white-space: nowrap;");
		oDescSpan.className="ms-menuitemdescription";
		oMenuItemBody.appendChild(oBold);
		oBold.appendChild(oTextSpan);
		oTextSpan.appendChild(oTextNode);
		oMenuItemBody.appendChild(oBr);
		oMenuItemBody.appendChild(oDescSpan);
		oDescSpan.appendChild(oDescNode);
	}
	else if (sText !=null)
	{
		var oTextSpan=document.createElement("SPAN");
		var oTextNode=document.createTextNode(sText);
		oTextSpan.setAttribute("style","white-space: nowrap;");
		oMenuItemBody.appendChild(oTextSpan);
		oTextSpan.appendChild(oTextNode);
	}
	var htmlSpan=document.createElement("SPAN");
	htmlSpan.innerHTML=innerHtml;
	oMenuItemBody.appendChild(htmlSpan);
	if (wzIconSrc)
	{
		var oImg=document.createElement("IMG");
		SetImageSize(oMaster, oImg);
		var oImgLbl=document.createElement("LABEL");
		oIcon.appendChild(oImg);
		oLabel.appendChild(oImgLbl);
		var wzIconId=wzID+"_"+"ICON";
		oImg.id=wzIconId;
		oImg.src=wzIconSrc;
		if (wzIconAlt)
		{
			oImg.alt="";
			oImg.title="";
		}
		oImgLbl.htmlFor=wzIconId;
		oImgLbl.appendChild(oMenuItemBody);
	}
	else
	{
		if (browseris.nav || oMaster._fLargeIconMode)
		{
			var oImg=document.createElement("IMG");
			SetImageSize(oMaster, oImg);
			var oImgLbl=document.createElement("LABEL");
			oIcon.appendChild(oImg);
			oLabel.appendChild(oImgLbl);
			var wzIconId=wzID+"_"+"ICON";
			oImg.id=wzIconId;
			oImg.src="/_layouts/images/blank.gif";
			oImg.alt="";
			oImg.title="";
			oImgLbl.htmlFor=wzIconId;
			oImgLbl.appendChild(oMenuItemBody);
			if (oMaster._fLargeIconMode)
			{
				oImg.width=32;
				oImg.height=16;
			}
			else
			{
				oImg.width=16;
			}
		}
		else
		{
			oIcon.innerHTML="&nbsp;";
			oLabel.appendChild(oMenuItemBody);
		}
	}
	var wzAccKey=oNode.getAttribute("accessKeyText");
	if (wzAccKey) oAccKey.innerHTML=wzAccKey;
	SetIType(oRow, "option");
}
function CreateMenuSeparator(oMaster, oRow)
{
	var oCell=document.createElement("td");
	var oDiv=document.createElement("div");
	oRow.appendChild(oCell);
	oCell.appendChild(oDiv);
	if (oMaster._fLargeIconMode)
		oDiv.className=!oMaster._fIsRtL ? "ms-MenuUISeparatorLarge" : "ms-MenuUISeparatorLargeRtl";
	else
		oDiv.className=!oMaster._fIsRtL ? "ms-MenuUISeparator" : "ms-MenuUISeparatorRtL";
	oDiv.innerHTML="&nbsp;";
	SetIType(oRow, "separator");
}
function CreateSubmenu(oMaster, oRow, oNode, wzID)
{
	var oLabelNode=FindLabel(oNode);
	CreateMenuOption(oMaster, oRow, oNode, wzID, oLabelNode ? oLabelNode.innerHTML : null);
	var oArrow=oRow.childNodes[3];
	var oArrowImg=document.createElement("IMG");
	SetImageSize(oMaster, oArrowImg, 16);
	oArrow.appendChild(oArrowImg);
	oArrowImg.src=!oMaster._fIsRtL ? oMaster._wzMArrPath : oMaster._wzMArrPathRtL;
	oArrowImg.alt=!oMaster._fIsRtL ? ">" : "<";
	oArrowImg.title="";
	SetIType(oRow, "submenu");
	oRow.submenuRoot=oNode;
}
function MergeAttributes(oTarget, oSource)
{
	if (browseris.nav || oTarget.mergeAttributes==null)
	{
		var oAttributes=oSource.attributes;
		for (var i=0; i < oAttributes.length; i++)
		{
			var oAttrib=oAttributes[i];
			if (oAttrib !=null &&
				oAttrib.specified &&
				oAttrib.nodeName !="id" &&
				oAttrib.nodeName !="ID" &&
				oAttrib.nodeName !="name")
			{
				oTarget.setAttribute(oAttrib.nodeName, oAttrib.nodeValue);
			}
		}
		if (oSource.getAttribute("type") !=null)
			oTarget.setAttribute("type", oSource.getAttribute("type"));
		if (oSource.submenuRoot !=null)
			oTarget.submenuRoot=oSource.submenuRoot;
	}
	else
	{
		oTarget.mergeAttributes(oSource);
	}
}
function CreateMenuItem(oMaster, oNode, wzID, wzHtml)
{
	if (FIsIType(oNode, "label")) return;
	var oRow=document.createElement("tr");
	MergeAttributes(oRow, oNode);
	oRow.setAttribute("onMenuClick", oNode.getAttribute("onMenuClick"));
	if (FIsIType(oNode, "separator"))
	{
		CreateMenuSeparator(oMaster, oRow);
		return oRow;
	}
	if (!GetIType(oNode)) SetIType(oNode, "option");
	var oFmtTableRow=document.createElement("tr");
	var oFmtTableCell=document.createElement("td");
	var oFmtTable=document.createElement("table");
	var oFmtTableBody=document.createElement("tbody");
	oFmtTableRow.appendChild(oFmtTableCell);
	oFmtTableCell.appendChild(oFmtTable);
	oFmtTable.appendChild(oFmtTableBody);
	oFmtTableBody.appendChild(oRow);
	if (oMaster._fCompactItemsWithoutIcons && !oNode.getAttribute("iconSrc"))
		oFmtTableCell.className="ms-MenuUIItemTableCellCompact";
	else
		oFmtTableCell.className="ms-MenuUIItemTableCell";
	oFmtTable.className="ms-MenuUIItemTable";
	oFmtTable.width="100%";
	oFmtTable.cellSpacing=0;
	oFmtTable.cellPadding=0;
	if (FIsIType(oNode, "submenu"))
		CreateSubmenu(oMaster, oRow, oNode, wzID);
	else if (FIsIType(oNode, "option"))
		CreateMenuOption(oMaster, oRow, oNode, wzID, wzHtml);
	if (oRow.disabled ||
		oRow.getAttribute("enabled")=="false")
	{
		oRow.disabled=false;
		oRow.className="ms-MenuUIDisabled";
		oRow.disabled=false;
		for (var nIndex=0; nIndex < oRow.childNodes.length; nIndex++)
		{
			if (oRow.childNodes[nIndex].nodeType !=1)
				continue;
			oRow.childNodes[nIndex].disabled=true;
			oFmtTableCell.className+=" ms-MenuUIItemTableCellDisabled";
		}
		oRow.optionDisabled=true;
	}
	MergeAttributes(oFmtTableRow, oRow);
	if (oRow.optionDisabled !=null)
	{
		oFmtTableRow.optionDisabled=oRow.optionDisabled;
	}
	oFmtTableRow.id=wzID;
	SetIType(oFmtTableRow, GetIType(oRow));
	return oFmtTableRow;
}
function GetItems(oMaster)
{
	if (!oMaster._oContents) PrepContents(oMaster);
	return oMaster._oContents.childNodes;
}
function GetIType(oItem)
{
	return oItem ? oItem.getAttribute("type") : null;
}
function FIsIType(oItem, wzType)
{
	return FIStringEquals(GetIType(oItem), wzType);
}
function SetIType(oItem, wzType)
{
	if (oItem) oItem.setAttribute("type", wzType);
}
function FIStringEquals(wzX, wzY)
{
	return wzX !=null && wzY !=null && wzX.toLowerCase()==wzY.toLowerCase();
}
function RenderAccessibleMenu(oMaster, fForceRefresh)
{
	if (fForceRefresh)
	{
		oMaster._oContents=null;
		oMaster._oRoot=null;
		oMaster._nLevel=0;
		oMaster._arrPopup=new Array();
		oMaster._arrSelected=new Array();
	}
	else
	{
		oMaster._oRoot=oMaster._oContents;
	}
	if (!oMaster._oContents) PrepContents(oMaster);
	if (!oMaster._oContents) return;
	if (!oMaster._oRoot)
	{
		oMaster._nLevel=0;
		oMaster._oRoot=oMaster._oContents;
	}
	FixUpMenuStructure(oMaster);
	var menuDir=oMaster._fIsRtL ? "rtl" : "ltr";
	g_menuHtc_html="<html dir='"+menuDir+"'><head><title>"+L_AccessibleMenu_Text+"</title></head><body><ul id='root'>";
	RenderMenuLevel(oMaster, oMaster._oRoot, true);
	g_menuHtc_html=g_menuHtc_html+"</ul></body></html>";
	var oNewWindow=window.open("/_layouts/blank.htm", "_blank", "status=no,toolbar=no,menubar=no,location=no");
	oMaster._accessibleMenu=oNewWindow;
	oNewWindow.document.write(g_menuHtc_html);
	oNewWindow.document.close();
	oNewWindow.focus();
}
function CloseAccessibleMenu(oMaster, n)
{
	if (n==null)
		n=0;
	if (oMaster !=null)
	{
		if (n==0 || n==1)
		{
			if (oMaster._accessibleMenu !=null)
			{
				oMaster._accessibleMenu.close();
				oMaster._accessibleMenu=null;
			}
		}
		if (n==0 || n==2)
		{
			if (oMaster._onDestroy !=null)
			{
				oMaster._onDestroy();
				oMaster._onDestroy=null;
			}
		}
	}
}
function GetMenuItemText(oMaster, oNode, s)
{
	if (s=="")
	{
		s=EvalAttributeValue(oNode, "text", "textScript");
		var description=EvalAttributeValue(oNode, "description", "descriptionScript");
		if (description !=null &&
			description !="" &&
			oMaster._fLargeIconMode)
		{
			if (s !="")
				s=s+": ";
			s=s+description;
		}
	}
	if (oNode.getAttribute("checked")=="true")
		s="* "+s;
	if (oNode.title !=null && oNode.title !="")
		s=s+": "+oNode.title;
	return s;
}
function GetMenuItemEnabled(oNode, fEnabled)
{
	if (!fEnabled)
		return false;
	if (oNode.getAttribute("enabled")=="false")
		return false;
	if (oNode.getAttribute("disabled") !=null && oNode.getAttribute("disabled") !="")
		return false;
	return true;
}
var g_menuHtc_html;
function RenderMenuLevel(oMaster, oRoot, fEnabled)
{
	for (var nIndex=0; nIndex < oRoot.childNodes.length; nIndex++)
	{
		var oNode=oRoot.childNodes[nIndex];
		if (oNode.nodeType !=1)
			continue;
		if (oNode.style.display=="none")
			continue;
		if (FIsIType(oNode, "option"))
		{
			var s=GetMenuItemText(oMaster, oNode, oNode.innerHTML);
			if (!GetMenuItemEnabled(oNode, fEnabled))
			{
				g_menuHtc_html=g_menuHtc_html+"<li><span id=\""
+oNode.id+"\">"
+s+"</span></li>";
			}
			else
			{
				g_menuHtc_html=g_menuHtc_html+"<li><a href=\"#\" id=\""
+oNode.id+"\" "
+"onMenuClick"
+"=\""
+oNode.getAttribute("onMenuClick")
+"\" onclick=\""
+"javascript:opener.ExecuteOnAccessibleClick(this.getAttribute('"+"onMenuClick"+"')); return false;"
+"\">"
+s
+"</a></li>";
			}
		}
		else if (FIsIType(oNode, "submenu"))
		{
			var s=GetMenuItemText(oMaster, oNode, "");
			g_menuHtc_html=g_menuHtc_html+"<li><span id=\""+oNode.id+"\">"+s;
			for (var n=0; n < oNode.childNodes.length; n++)
			{
				var oLabelNode=oNode.childNodes[n];
				if (oLabelNode.nodeType !=1)
					continue;
				if (oLabelNode.style.display=="none")
					continue;
				if (FIsIType(oLabelNode, "label"))
				{
					g_menuHtc_html=g_menuHtc_html+" "+oLabelNode.innerHTML;
					break;
				}
			}
			g_menuHtc_html=g_menuHtc_html+"</span><ul>";
			RenderMenuLevel(oMaster, oNode, GetMenuItemEnabled(oNode, fEnabled));
			g_menuHtc_html=g_menuHtc_html+"</ul></li>";
		}
	}
}
function ExecuteOnAccessibleClick(fnOnClick)
{
	var oMaster=g_menuHtc_lastMenu;
	if (oMaster !=null)
	{
		CloseAccessibleMenu(oMaster, 1);
		window.focus();
		ExecuteOnClick(fnOnClick);
		CloseAccessibleMenu(oMaster, 2);
	}
}
function FIsIHidden(oItem)
{
	if (oItem)
	{
		var hiddenFunc=oItem.getAttribute("hidden");
		if (!hiddenFunc) return false;
		return eval(hiddenFunc);
	}
	else
		return false;
}
function EvalAttributeValue(oNode, sAttribute1, sAttribute2)
{
	var result=oNode.getAttribute(sAttribute2);
	if (result !=null &&
		result.toLowerCase().indexOf("javascript:")==0)
	{
		result=eval(result.substring(11));
		if (result !=null && result !="")
			return result;
	}
	var result=oNode.getAttribute(sAttribute1);
	if (result==null)
		return "";
	return result;
}
var flyoutsAllowed=false;
function enableFlyoutsAfterDelay()
{
	setTimeout("flyoutsAllowed=true;", 25);
}



//---- VC Function -------------------------------------------------------------------------
//Added by QuyTD

String.prototype.trim = function() 
      {
        return this.replace(/^\s+/, '').replace(/\s+$/, '');        
      };

    function GetControlByName(id)
    {
        var prefix = document.getElementById("hidPrefix").value;
        return document.getElementById(prefix + id);
    }
    function VC_Requirefield(field,msg)
    {
        var control = GetControlByName(field)
        if (control) control.value = control.value.trim();
        if (control != null && control.value.length == 0)
        {
            AlertAndSetFocus(control,msg);            
            return false;
        }
        return true;
    }
    
    function VC_Combobox_Req(field,msg)
    {
        var control = GetControlByName(field)        
        if (control != null && (control.selectedIndex  == -1  || control.options[control.selectedIndex].value == ""))
        {
            AlertAndSetFocus(control,msg);            
            return false;
        }
        return true;
    }
    
    function VC_Combobox_Require(field,msg)
    {
        var control = document.getElementById(field)  ;    
        alert(control);  
        if (control != null && (control.selectedIndex  == -1  || control.options[control.selectedIndex].value == "" || control.options[control.selectedIndex].value == "0"))
        {
            AlertAndSetFocus(control,msg);            
            return false;
        }
        return true;
    }
    
    function AlertAndSetFocus(ctr,msg)
    {        
        ctr.focus();
        alert(msg);
    }
    
    
    function IsFileExist(source)
    {
        return true;
        //var fso = new ActiveXObject("Scripting.FileSystemObject");        
        //return fso.FileExists(source);
    }
    
    
    function GetIndexOfCombobox(cbo)
    {
        var cb = GetControlByName(cbo);
        if (cb)
        {
            var list = cb.getElementsByTagName("input");
            for (var i =0 ; i< list.length; i++)
            {
                if (list[i].checked) return i;
            }
        }
        return -1;
    }
    
    
    function VC_IsNumber(ctr,msg)
	{
	    var w = ctr.value;
	    if (w == "" || w == null) return true;
		try
		{
		    
			if (isNaN(w))
			{
			    alert(msg);		    
		        ctr.focus();
		        ctr.select();
			    return false;
			}
			else
			{
			    return true;
			}
		}
		catch(e)
		{
		    alert(msg);		    
		    ctr.focus();
		    ctr.select();
			return false;
		}
	}
	
	function BuildURL(level1,level2,level3,text2,text3)
	{
	    var ctr = document.getElementById("pnHeader");
	    strTable = "<table><tr><td></td><tr></table>";
	    ctr.outerHTML  = strTable;
	}
	function BuildLink(url,text)
	{
	    return "<a href=\"" + url + "\">" + STSHtmlEncode(text) + "</a>";
	}
	//window.attactEvent("onload",BuildLink('','','','',''));
	function VCGoToPage(url)
    {
        location.href = url;
    }
    
    function ImgResize(imgPath,thumbSize){
        
            document.getElementById("loginForm").style.top = "100px";
            document.getElementById("loginForm").style.left = "400px";
            document.getElementById("loginForm").style.visibility = "visible";
            document.getElementById("loginForm").style.display="inline";
            document.getElementById("loginForm").style.position ="absolute";
            document.getElementById("fPic").src = imgPath;
            
            var newImg=new Image();
            newImg.src=imgPath;
            var _width=newImg.width;
            var _height=newImg.height;
            
            if(_width>thumbSize)
            {
                _height=Math.round(_height*thumbSize/_width);
                _width=thumbSize;
            }
            else if(_height>thumbSize)
            {
                _width=Math.round(_width*thumbSize/_height);
                _height=thumbSize;
            }
            
            if(_width == 0 || _height == 0)
            {
                 newImg.src=imgPath;
                _width=newImg.width;
                _height=newImg.height;
            }
            else
            {
                var currImg=document.getElementById("fPic");
                currImg.src=newImg.src;
                currImg.width=_width;
                currImg.height=_height;
            }
        }
        
        function ImgResizeViewByList(imgPath,thumbSize){
        
            document.getElementById("loginForm").style.top = "50px";
            document.getElementById("loginForm").style.left = "50px";
            document.getElementById("loginForm").style.visibility = "visible";
            document.getElementById("loginForm").style.display="inline";
            document.getElementById("loginForm").style.position ="absolute";
            document.getElementById("fPic").src = imgPath;
            
            var newImg=new Image();
            newImg.src=imgPath;
            var _width=newImg.width;
            var _height=newImg.height;
            
            if(_width>thumbSize)
            {
                _height=Math.round(_height*thumbSize/_width);
                _width=thumbSize;
            }
            else if(_height>thumbSize)
            {
                _width=Math.round(_width*thumbSize/_height);
                _height=thumbSize;
            }
            
            if(_width == 0 || _height == 0)
            {
                 newImg.src=imgPath;
                _width=newImg.width;
                _height=newImg.height;
            }
            else
            {
                var currImg=document.getElementById("fPic");
                currImg.src=newImg.src;
                currImg.width=_width;
                currImg.height=_height;
            }
        }
        
        function CloseFormImage(){
            document.getElementById("fPic").src = "";
            document.getElementById("loginForm").style.visibility = "hidden";
        }
        
        function playMedia(mediaPath){
        
            flashPath = flashPath.toLowerCase();
            
            document.getElementById("divFlash").style.top = "100px";
            document.getElementById("divFlash").style.left = "400px";
            document.getElementById("divFlash").style.visibility = "visible";
            document.getElementById("divFlash").style.display="inline";
            document.getElementById("divFlash").style.position ="absolute";
            
            if(flashPath.indexOf('.swf') > 0)
            {
                var so = new SWFObject(flashPath, "sotester", "300", "300", "9");
                so.write("flashcontent");
            }
            else
            {
                
                var sFlashPlayer144 = new SWFObject("/images/portal/share/mediaplayer.swf","playlist","300","300","9");
                sFlashPlayer144.addParam("allowfullscreen","true");
                sFlashPlayer144.addVariable("file",flashPath );
                sFlashPlayer144.addVariable("displayheight","300");
                sFlashPlayer144.addVariable("width","300");
                sFlashPlayer144.addVariable("height","300");
                sFlashPlayer144.addVariable("backcolor","0x00407F");
                sFlashPlayer144.addVariable("frontcolor","0xFEFEFE");
                sFlashPlayer144.addVariable("lightcolor","0xFFFFFF");
                sFlashPlayer144.addVariable("shuffle","false");
                sFlashPlayer144.addVariable("autostart","true");
                sFlashPlayer144.addVariable("repeat","list");
                sFlashPlayer144.write("flashcontent");
                
            }
        }
        
        function playMediaByViewList(mediaPath){
        
            flashPath = flashPath.toLowerCase();
            
            document.getElementById("divFlash").style.top = "50px";
            document.getElementById("divFlash").style.left = "50px";
            document.getElementById("divFlash").style.visibility = "visible";
            document.getElementById("divFlash").style.display="inline";
            document.getElementById("divFlash").style.position ="absolute";
            
            if(flashPath.indexOf('.swf') > 0)
            {
                var so = new SWFObject(flashPath, "sotester", "300", "300", "9");
                so.write("flashcontent");
            }
            else
            {
                
                var sFlashPlayer144 = new SWFObject("/images/portal/share/mediaplayer.swf","playlist","300","300","9");
                sFlashPlayer144.addParam("allowfullscreen","true");
                sFlashPlayer144.addVariable("file",flashPath );
                sFlashPlayer144.addVariable("displayheight","300");
                sFlashPlayer144.addVariable("width","300");
                sFlashPlayer144.addVariable("height","300");
                sFlashPlayer144.addVariable("backcolor","0x00407F");
                sFlashPlayer144.addVariable("frontcolor","0xFEFEFE");
                sFlashPlayer144.addVariable("lightcolor","0xFFFFFF");
                sFlashPlayer144.addVariable("shuffle","false");
                sFlashPlayer144.addVariable("autostart","true");
                sFlashPlayer144.addVariable("repeat","list");
                sFlashPlayer144.write("flashcontent");
                
            }
        }
        
        function CloseFormMedia(){
            mediaPlayer.stop();
            document.getElementById("divMedia").style.visibility = "hidden";
        }
        
              
        function playFlash(flashPath){
            
            document.getElementById("divFlash").style.top = "100px";
            document.getElementById("divFlash").style.left = "400px";
            document.getElementById("divFlash").style.visibility = "visible";
            document.getElementById("divFlash").style.display="inline";
            document.getElementById("divFlash").style.position ="absolute";
            var so = new SWFObject(flashPath, "sotester", "300", "300", "9");
            so.write("flashcontent");
        }
        
        function playFlashByViewList(flashPath){
            
            document.getElementById("divFlash").style.top = "50px";
            document.getElementById("divFlash").style.left = "50px";
            document.getElementById("divFlash").style.visibility = "visible";
            document.getElementById("divFlash").style.display="inline";
            document.getElementById("divFlash").style.position ="absolute";
            var so = new SWFObject(flashPath, "sotester", "300", "300", "9");
            so.write("flashcontent");
        }
        
        function CloseFormFlash(){
            document.getElementById("flashcontent").innerHTML = "";
            document.getElementById("divFlash").style.visibility = "hidden";
        }
        
        function ViewImage(imagePath){
            
            document.getElementById("divViewImage").style.top = "50px";
            document.getElementById("divViewImage").style.left = "50px";
            document.getElementById("divViewImage").style.visibility = "visible";
            document.getElementById("divViewImage").style.display="inline";
            document.getElementById("divViewImage").style.position ="absolute";
            var so = new SWFObject(flashPath, "sotester", "300", "300", "9");
            so.write("flashcontent");
        }
        
        
        function SelectAll(ctr,isCheck)
        {
            var chkList = document.getElementsByName("chkSelect");
            for (var i = 0 ; i < chkList.length; i++)
            {
                if (ctr != null)
                    chkList[i].checked = ctr.checked;
                else
                {
                    chkList[i].checked = isCheck;
                    var checkall = document.getElementById("chkAll");
                    if (checkall) checkall.checked = isCheck;
                    
                }
                
            }            
            return false;
        }
        
        function SelectOne()
        {
            var chkList = document.getElementsByName("chkSelect");
            var isCheck = true;
            for (var i = 0 ; i < chkList.length; i++)
            {
                if (!chkList[i].checked) isCheck = false;                
            }            
            document.getElementById("chkAll").checked = isCheck;
            return false;
        }
        
        
        function VC_ResizeImage(img,width)
        {
            var w = eval(img.style.width.replace("px",""));
            var h = eval(img.style.height.replace("px",""));
            if (eval(w) < width  && eval(h) < width) return;
            if (eval(w) > eval(h))
            {
                img.style.width = (width - 10) + "px";
            }
            else
            {
                img.style.height = (width - 10) + "px";
            }
            img.style.border = "1px";
        }
            
     
       // ----    Danh cho NewList 
       //khi nguoi dung click vao tin tieu diem
       var msg_confirm = "Bạn có muốn thay đổi không";
        function isCheckClick(ctr)
        {
            if (confirm(msg_confirm))
            {            
                var name = ctr.name;            
                __doPostBack(name.replace("chkIsFocus","btnUpdate"),'');           
            }
            else
            {            
                ctr.checked = !ctr.checked;
            }
            
        }
        //khi nguoi dung click vao combobox loai tin
        function isDropdownClick(ctr)
        {        
            if (confirm(msg_confirm))
            {            
                var name = ctr.name;            
                __doPostBack(name.replace("cboIsHot","btnUpdate"),'');           
            }
            else
            {            
                ctr.selectedIndex = eval(ctr.getAttribute("default"))
            }            
        }
        
        //--
        var ListsExtFile = "jpg,npg,bmp,abc";
        function ValidFileUpload(ctr)
        {
            var control = document.getElementById(ctr);
            var fileSrc = cotrol.value;
            var ext = fileSrc.substr(fileSrc.lastIndexOf(".") + 1,fileSrc.substr - fileSrc.lastIndexOf(".") - 1) + ",";                       
            ListsExtFile = ListsExtFile + ",";
            if (ListsExtFile.indexOf(ext) != -1) return true;
            return false;
        }
        
        
        function SetReadOnly(ctr)
        {
            var e = window.event;
            e.keyCode = 0;
        }
        
        
        var max = 999999;
	var min = -999999;
	var msgmax = "Ban nhap so to qua";
	var msgmin = "Ban nhap so nho qua";
	//<input type=text onkeypress="VCNumericControl(this,false)" onblur="VCNumericControl(this,true)" oncontextmenu = "return false;" onpaste="return false;" />
	function VCNumericControl(id,isvalidate)
	{
		try
		{			
			var e = window.event;			
			var code = e.keyCode;			
			if (code < 45 || code > 57) e.keyCode =0;

			if (code == 47) e.keyCode = 0;
			var vl = id.value;
		
			if (vl.length ==0) return;
			if (code == 45) 
			{
				e.keyCode = 0;
				id.value = "-" + vl.replace("-","");
			}
			if (code == 4 && vl.indexOf(".") != -1) 
			{			
				e.keyCode = 0;
			}
			vl = id.value;
			if (isvalidate && (vl.indexOf("-.")!= -1) && (vl.length == 2)) {id.value = "";}
			if (isvalidate  && eval(vl) < eval(min)) 
			{
				alert(msgmin);
				e.keyCode = 0;
				id.select();
				id.focus();
			}
			
			if (isvalidate && eval(vl) > eval(max)) 
			{
				alert(msgmax);
				e.keyCode = 0;
				id.select();
				id.focus();
			}            
		}
		catch(e)
		{			
			id.value = "";
		}
	}
